I tried both default credential and user/pass but keep getting 401 unauthorized error. What's the fix?
Here is the error I am getting ....
New-WebServiceProxy : The request failed with HTTP status 401: Unauthorized.
At C:\Scripts\GetItemID_UsingWebServices.ps1:1 char:26
+ $WS = New-WebServiceProxy <<<< -uri http://server/sites/promo/_vti_bin/SiteData.asmx
+ CategoryInfo : ObjectNotFound: (http://server...n/SiteData.asmx:Uri) [New-WebServiceProxy], WebExcept
ion
+ FullyQualifiedErrorId : WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
Property 'Credentials' cannot be found on this object; make sure it exists and is settable.
At C:\Scripts\GetItemID_UsingWebServices.ps1:2 char:5
+ $WS. <<<< Credentials = [System.Net.CredentialCache]::DefaultCredentials
+ CategoryInfo : InvalidOperation: (Credentials:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Scripts\GetItemID_UsingWebServices.ps1:12 char:26
+ $GUS = $WS.GetURLSegments <<<< ($ItemURL, $webID, $bucketID, $strListID, $strItemID)
+ CategoryInfo : InvalidOperation: (GetURLSegments:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Code:
$WS = New-WebServiceProxy -uri http://server/_vti_bin/SiteData.asmx
$WS.Credentials = [System.Net.CredentialCache]::DefaultCredentials
#$WS.Credentials = [System.Net.NetworkCredential]::("user", (ConvertTo-SecureString "password" -AsPlainText -force), "domain")
$ItemURL = "http://server/sites/promo/sales/testLib/TestFile.txt"
$GUS = $WS.GetURLSegments($ItemURL, $webID, $bID, $strListID, $strItemID)
Write-Host $strItemID
Update with new code!
This code is working (meaning at least no more 401 error). However, I am still working on it since it does not return any values for webid or bid or listid or itemid.
$webID = $null
$bID = $null
$strListID = $null
$strItemID = $null
$GUS
$uri = "http://Server/sites/Promo/TestDocLibrary44/_vti_bin/SiteData.asmx"
$WS = New-WebServiceProxy -uri $uri -UseDefaultCredential
$ItemURL = "http://Server/sites/Promot/TestDocLibrary44/2011102100006b.pdf"
$GUS = $WS.GetURLSegments($ItemURL, [REF]$webID, [REF]$bID, [REF]$strListID, [REF]$strItemID)
write-Host $strItemID.value # returning null or blank
write-Host $webID # returning null or blank
Write-Host "Test "