on 01-24-2014 04:33 PM
below code worked for me.
#Powershell script to export users from CUC unity connection API
"UserYourApiPassword" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File C:\apiuserpw.txt
$cucUsername = "ApiUserName"
$cucpwd = Get-Content C:\apiuserpw.txt
$securepwd = $cucpwd | ConvertTo-SecureString
$cucCred = new-object -typename System.Management.Automation.PSCredential -ArgumentList ($cucUsername,$securepwd)
#add dotnet cert obj to avoid the cert errors
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$urlresponse = Invoke-WebRequest -Credential $cucCred -Uri "https://xx.xx.xx.xx/vmrest/users?rowsPerPage=1" -UseBasicParsing
if($urlresponse.StatusCode -eq 200){
Write-Host "Connected"
$x = 0
$userdata = @()
do{
$x++
Write-Host "page Number $x"
$userurl = Invoke-RestMethod -Credential $cucCred -Uri "https://xx.xx.xx.xx/vmrest/users?rowsPerPage=100&pageNumber=$x"
$userdata += $userurl.Users.User
}while($userurl.Users.User.Length -eq 100)
}
else{Write-Host "Unable to Connect" }
#export Data to csv File
$userdata |Export-Csv cucuserdata.csv -NoTypeInformation
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: