#requires -version 2.0 [CmdletBinding()] param ( [parameter(Mandatory=$true)] [ValidatePattern('^https?://')] [string] $Uri, [parameter( ParameterSetName='ReportService2010', Mandatory=$true)] [string] $Version, [System.Management.Automation.PSCredential] $Credential ) $script:ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest if (-not $Uri.EndsWith('.asmx')) { if (-not $Uri.EndsWith('/')) { $Uri += '/' } if($Version -eq 'ReportService2010'){ $Uri += 'ReportService2010.asmx?WSDL' } else { $Uri += 'ReportService2005.asmx' } } $Assembly = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { if($Version -eq 'ReportService2010'){ $_.GetType('SSRS.ReportingService2010.ReportingService2010') } else { $_.GetType('SSRS.ReportingService2010.ReportingService2005') } } if (($Assembly | Measure-Object).Count -gt 1) { throw 'AppDomain contains multiple definitions of the same type. Restart PowerShell host.' } if (-not $Assembly) { if ($Credential) { $CredParams = @{ Credential = $Credential } } else { $CredParams = @{ UseDefaultCredential = $true } } if($Version -eq 'ReportService2010'){ $Proxy = New-WebServiceProxy -Uri $Uri -Namespace SSRS.ReportingService2010 @CredParams } else { $Proxy = New-WebServiceProxy -Uri $Uri -Namespace SSRS.ReportingService2005 @CredParams } } else { if($Version -eq 'ReportService2010'){ $Proxy = New-Object -TypeName SSRS.ReportingService2010.ReportingService2010 } else { $Proxy = New-Object -TypeName SSRS.ReportingService2005.ReportingService2005 } if ($Credential) { $Proxy.Credentials = $Credential.GetNetworkCredential() } else { $Proxy.UseDefaultCredentials = $true } } $Proxy.Url = $Uri return $Proxy