Quantcast
Channel: VMware Communities : Discussion List - vSphere SDK for Perl
Viewing all articles
Browse latest Browse all 1577

SOAP API PowerShell Stopped Working

$
0
0

This script used to work fine for 4.0.1 but now I'm getting an error with 4.0.4.

 

Script (Works with 4.0.1)

 

function New-ObjectFromProxy {
    param($proxy, $proxyAttributeName, $typeName)
   
    # Locate the assembly for $proxy
    $attribute = $proxy | gm | where { $_.Name -eq $proxyAttributeName }
    $str = "`$assembly = [" + $attribute.TypeName + "].assembly"
    invoke-expression $str
    # Instantiate an AuthenticationHeaderValue object.
    $type = $assembly.getTypes() | where { $_.Name -eq $typeName }
    return $assembly.CreateInstance($type)
}

function Get-LabManagerInternal {
    param (
        [string] $server = $(throw "Parameter -Server [System.String] is required."),
        $credential = $(get-credential),
        [string] $organizationname = "Global",
        [string] $workspacename = "Main"
    )
    # Ignore SSL Errors
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
   
    $labManagerInternalUri = [System.Uri] "https://$server/LabManager/SOAP/LabManagerInternal.asmx"
    $proxy = New-WebServiceProxy -Uri $labManagerInternalUri -Credential $credential
   
    if ($proxy) {
        # Before continuing we need to add an Authentication Header to $proxy.
        $authHeader = New-ObjectFromProxy -proxy $proxy -proxyAttributeName "AuthenticationHeaderValue" -             typeName "AuthenticationHeader"
        $authHeader.username = $credential.GetNetworkCredential().UserName
        $authHeader.password = $credential.GetNetworkCredential().Password
        $authHeader.organizationname = $organizationname
        $authHeader.workspacename = $workspacename
        $proxy.AuthenticationHeaderValue = $authHeader
        return $proxy
    }
}
Error:
Exception setting "AuthenticationHeaderValue": "Cannot convert the "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.AuthenticationHeader" value of type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.AuthenticationHeader" to type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.AuthenticationHeader"."

Which doesn't make any sense...


Viewing all articles
Browse latest Browse all 1577

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>