1

I am struggling with a script that queries Sharepoint.

This script is supposed to query a sharepoint list, then generate an output and then patch the servers. Here is the part i am struggling with..
When i run it i get this error:

Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.So apServer.SoapServerException' was thrown." At C:\Scripts\AUpdate\iPatch2.ps1:472 char:33 + $list = $SiteWS.GetListItems <<<< ($ListName,$ViewGuid,$query,$null,$null,$queryOptions,$nul l) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

Can anyone help please?

# Gather a list of servers to be patched from a Sharepoint list
function Get-PatchList {
param ( [string] $Uri = 'http://site/_vti_bin/lists.asmx?wsdl', 
        [string] $Day = $(throw "The Day parameter is required"),
        [string] $Time = $(throw "The Time parameter is required"), 
        [System.Management.Automation.PSCredential] $Credential, 
        [string] $ViewGuid = '{1DD35D95-E1CB-4DFA-8EFD-63C9342C524A}', 
        [string] $ListName = 'Automated Patching' )

# initialise return object
$out = @()

# connect to web service
$SiteWS = New-WebServiceProxy -Uri $Uri -Credential $Credential
Write-Verbose "Connecting to web service at $Uri" 
Write-Verbose " Connecting using $($Credential.username)"
Write-Verbose " Filtering hosts managed by $thisHost"

# Get the list
[System.Xml.XmlNode] $queryOptions
[System.Xml.XmlNode] $viewFields
#[System.Xml.XmlNode] $query = [xml]"<Query><Where><And><And><Eq><FieldRef Name='TOD'/><Value Type='Text'>$Time</Value></Eq><Eq><FieldRef Name='Day'/><Value Type='Text'>$Day</Value></Eq></And><Or><Eq><FieldRef Name='Status'/><Value Type='Text'>ON</Value></Eq><Eq><FieldRef Name='Status'/><Value Type='Text'>ON In Production</Value></Eq></Or></And></Where></Query>"
[System.Xml.XmlNode] $query = [xml]"<Query><Where><And><And><And><Eq><FieldRef Name='TOD'/><Value Type='Text'>$Time</Value></Eq><Eq><FieldRef Name='Day'/><Value Type='Text'>$Day</Value></Eq></And><Or><Eq><FieldRef Name='Status'/><Value Type='Text'>ON</Value></Eq><Eq><FieldRef Name='Status'/><Value Type='Text'>ON In Production</Value></Eq></Or></And><Eq><FieldRef Name='Server'/><Value Type='Text'>$thisServer</Value></Eq></And></Where></Query>"

$list = $SiteWS.GetListItems($ListName,$ViewGuid,$query,$null,$null,$queryOptions,$null)
#Write-Verbose "Retrieving data with filter " $query

#Parse through the list
foreach ($row in $list.data.row) {
    $myhost = New-Object PatchableServer
    $myhost.Host = $row.ows_Title
    $myhost.Domain = $row.ows_Domain
    $myhost.Services = $row.ows_TS
    $myhost.Impact = $row.ows_Impact
    $out = $out + $myhost
    }
 return $out
}

# Reformat the list of services from the MOSS format to human-readable


function Parse-Services {
param ( [string] $Services )

[string] $out = ""

if ($Services) {
    $split = $Services.Split('#')
    $len = $split.Length
    if ($len -lt 2) {return $null}
    else {
        for ($i=1; $i -le $len; $i+=2)
            {$out +=  $split[$i]}
        return $out
        }
    }
else {
    return $null
    }
}

function Resolve-FQDN {
param ([string] $Identifier)
$myhost = [System.Net.Dns]::GetHostEntry($Identifier)
return $myhost.HostName
}

function Get-HostDomain {
param([string] $Hostname)
$fqdn = Resolve-FQDN -Identifier $Hostname
return $fqdn.TrimStart($Hostname).TrimStart('.')
}

function Get-Ping {
param ([string] $Hostname)
$myhost = gwmi Win32_PingStatus -Filter "Address='$Hostname'"
if ($myhost) { return $myhost.ResponseTime }
else { return $null }
}

1 Answer 1

1

I've had no end of issues working with List Names that have spaces in them.

[string] $ListName = 'Automated Patching' )

Clone the list and check that out first. I've wasted enough time with that issue that I always try it first. If it that is the case, you can either figure out the evil nested quoting they use for spaces or re-implement with the space-free name. (You can change the DISPLAY of the name to have a space without changing the fundamental name used when you create the list... it will still look good to the boss. ;-)

update IIRC you can try the URL quoting first 'Automated%20Patching', that often is enough.

1
  • Ahh. That worked perfectly... Thanks for that.....
    – user98805
    Oct 25, 2011 at 10:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .