############################################################################################
# Create $list of server names - in Service Catalog where status equals selection
#
[array]$list = $null
$uri = "http://portal/apps/systemscatalog/_vti_bin/lists.asmx?WSDL"
$listName = "Server Catalog"
# Create xml query - get the whole list
$xmlDoc = new-object System.Xml.XmlDocument
$query = $xmlDoc.CreateElement("Query")
$vfxml = "" +
" " +
" " +
" " +
" "
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$query.set_InnerXml("FieldRef Name='Full Name'")
$rowLimit = "3000"
$serverlist = $null
$service = $null
try{
$service = New-WebServiceProxy -Uri $uri -Namespace SpWs -UseDefaultCredential
}
catch{
Write-Error $_ -ErrorAction:'SilentlyContinue'
}
if($service -ne $null){
try{
$serverlist = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, $null)
}
catch{
Write-Error $_ -ErrorAction:'SilentlyContinue'
}
}
$output = $serverlist.data.row
if ( -not $output) {
clear-host
"ERROR: No output from sharepoint"
"ERROR: No output from sharepoint" | out-file $logfile -append
exit
}
[string]$status = $null
foreach ($item in $output) {
[string]$status = $item.ows_DeploymentStatus
$Server = $item.ows_Title
$dmz = $item.ows_IsDMZServer
if ($dmz -eq $null) { $dmz = 0 }
if($status -eq $selection) {
if ($filterDMZ -and (-not $dmz)) {
if ($Server) { $list = $list + $Server} #skip a null value
}#end if
else {
if ($Server) { $list = $list + $Server} #skip a null value
}
}#end if
[string]$status = $null
} #end foreach
#
$list = $list | sort-object
if ( -not $list) {
"ERROR: No server list to check"
"ERROR: No server list to check" | out-file $logfile -append
exit
}
1/12/2015
powershell query remote sharepoint
Example of query to a sharepoint list on a remote machine.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment