Param( [Parameter (Mandatory = $false, HelpMessage = "Enter the location of the Cerberus.wsdl file. May be a URL or a filesystem path." )] # By default, the WSDL file is served from the HTTPS Admin port by Cerberus # Server If the Admin interface has been changed in your Cerberus # environment and/or Cerberus is not running locally, change the below URL # to suit your environment [String] $WSDLUrl = "https://localhost:8443/wsdl/Cerberus.wsdl" , [Parameter (Mandatory = $false)] # If credentials are not provided the user will be prompted to provide them [PSCredential] $CerberusCredentials , [Parameter (Mandatory = $false)] # Cerberus FTP Server version 10.0.10 and later automatically publish the # correct service endpoint. If you are running an earlier version of # Cerberus the correct endpoint will need to be provided. Consult the # Remote, SOAP Admininstration Settings page for the correct URL The # out-of-the-box default is provided below for reference # "http://localhost:10001/service/cerberusftpservice" [String] $CerberusServiceUrl ) if (-not $PSBoundParameters.containsKey('CerberusCredentials')) { $CerberusCredentials = Get-Credential -Message "Provide master admin credentials for Cerberus FTP Server" } # This function allows PowerShell to make SSL connections using Tls1.2, which is disabled by default function Enable-Tls12 { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } # Cerberus may use a self-signed certificate when running outside of a # production environment. This certificate will be rejected when making HTTPS # connections to the WSDL and SOAP service URL, failing the operation. The # following function disables certificate validation for the current PowerShell # session, allowing access to these resources. function Disable-CertificateValidation { if (-not("dummy" -as [type])) { add-type -TypeDefinition @" using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public static class Dummy { public static bool ReturnTrue(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; } public static RemoteCertificateValidationCallback GetDelegate() { return new RemoteCertificateValidationCallback(Dummy.ReturnTrue); } } "@ } [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate() } # Call this function before New-WebServiceProxy if Cerberus' SOAP endpoint uses HTTPS Enable-Tls12 # Call this function before New-WebServiceProxy if Cerberus is using a self-signed certificate Disable-CertificateValidation # New-WebServiceProxy creates a service proxy object for calling Cerberus SOAP # APIs. Dependent classes are also created and placed in the "CerberusFtp" # namespace. $CerberusSvc = New-WebServiceProxy -Uri $wsdlUrl -Class CerberusFtp -Namespace CerberusFtp # Override the endpoint URL if it has been provided in parameters if ($PSBoundParameters.containsKey('CerberusServiceUrl') -eq $true){ $CerberusSvc.Url = $CerberusServiceUrl } # Populate a request object with Cerberus credentials $request = @{ credentials=@{ user=$CerberusCredentials.UserName; password=$CerberusCredentials.GetNetworkCredential().password } } # Call the Cerberus SOAP operation on the proxy object, passing the request $infoResponse = $CerberusSvc.ServerInformation($request) # Display the 'result' member of the response and 'result.version' details $infoResponse.result $infoResponse.result.version