CUCMSidecarWorkflow/Private/Get-DeviceInfo.ps1
|
function Get-DeviceInfo { <# .SYNOPSIS Retrieves information about a device from CUCM. .DESCRIPTION Get-DeviceInfo creates a SOAP Request (provided correct credentials and a valid device are given) to Cisco Unified Communications Manager's (CUCM) AXL API If successful, it stores the device information in an XML document on the user's desktop. It then asks the user whether he or she wishes to add or remove a directory from the sidecar of the device. Depending on the choice, it will call Add-UserToSideCar or Remove-UserFromSideCar. .PARAMETER DeviceName The Cisco device (phone) to be updated. .PARAMETER FileName The XML document which holds the infomation of the device to be updated. Created from the SOAP response given from the AXL API. Default is "C:\Users\$env:USERNAME\Desktop\phoneInfo.xml" .PARAMETER cred The credentials given by the user in Edit-SideCar. Needed to continue accessing the CUCM isntance for invoking the API. #> [CmdletBinding()] Param ( [string]$DeviceName, [string]$FileName ="C:\Users\$env:USERNAME\Desktop\DeviceInfo.xml", [System.Management.Automation.PSCredential] $cred ) BEGIN{} PROCESS { $CUCMServer = "InstanceOfCUCMServerHere" #TODO: Add your CUCM instance. [xml]$request = @" <?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns='http://www.cisco.com/AXL/API/10.0'> <soapenv:Body> <ns:getPhone sequence="?"> <name>$DeviceName</name> </ns:getPhone> </soapenv:Body> </soapenv:Envelope> "@ $headers= @{ 'Content-Type'='text\xml;charset=UTF-8'; 'SOAPAction'='CUCM:DB ver 11.0'; } # Required to ignore some HTTP errors [System.Net.ServicePointManager]::Expect100Continue = $false # Reset $result in case Invoke-WebRequest errors $result = $null #Invoking Request TO API $result = Invoke-RestMethod -Method Post -Uri "https://$CUCMServer`:8443/axl/" -Headers $headers -Body $request -Credential $cred [void]$result.Envelope.Body.getPhoneResponse.return.phone [xml]($result.Save($FileName)) }#PROCESS END{} } |