CPSM API Functions 1


Citrix Cloud Portal Services Manager –  API Functions…. Have you also tried to figure out how the f*** can i do this and that with the API?

I have!

The documentation provided by Citrix is just not that good. I’ve created a PowerShell app for my needs, below is a collection of the functions i’ve figured out how to use..

#First, set your variables#

#$apiUsername = "user@yourdomain.com"
#$apiPassword = "Pa$$W0rd"
$apiUrl = "https://cpsm.yourdomain.com/cortexapi/default.aspx"

#DoRequest – This is the base function, you need this!#

Function DoRequest()
{
Param(
[string]$request = $(throw "request required")
)

$client = new-object System.Net.WebClient
$client.Encoding = [System.Text.Encoding]::UTF8
$client.Credentials = New-Object System.Net.NetworkCredential($apiUsername,$apiPassword)
$response = $client.UploadString($apiUrl,$request);
return $response;
}
#End DoRequest#

#GetCustomers – Finds all the customers in your CPSM environment#

Function GetCustomers()
{

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->



"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;
return $req.response.customer
}
#End GetCustomers#

#GetCustomer – Uses the GET command to get more detailed information about a specific customer#

Function GetCustomer()
{
Param(
[string]$customerFullName = $(throw "customerFullName required")
)

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerFullName


"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;
return $req.response.customer
}
#End GetCustomer#

#GetCustomerServices – Lists all the services provisioned to a specific customer#

Function GetCustomerServices()
{
Param(
[string]$customerName = $(throw "customerName required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

Provisioned



"@;

$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;
return $req.response.customer.service.fullname
}
#End GetCustomerServices#

#GetHostedLyncLic – Get’s the Lync licenses assigned to a specific customer#

Function GetHostedLyncLic()
{
Param(
[string]$customerName = $(throw "customerName required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

LyncHosted



"@;

$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;
return $req.response.customer.service.userplan
}
#End GetHostedLyncLic#

#GetDesktopOfferings – Get’s all the offerings (Citrix Apps) provisioned to a specific customer#

Function GetDesktopOfferings()
{
Param(
[string]$customerName = $(throw "customerName required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

HostedAppsandDesktops




"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;
return $req.response.customer.service.offerings.offering
}
#End GetDesktopOfferings#

#CreateUser – My version on creating a user with the ad attributes we mostly use#

Function CreateUser()
{
Param(
[string]$customerName = $(throw "customerName required"),
#[string]$U_Name = $(throw "UserName required"),
[string]$U_FullName = $(throw "UserFullname required"),
[string]$U_FirstName = $(throw "UserFirstname required"),
[string]$U_LastName = $(throw "UserLastname required"),
[string]$U_UPN = $(throw "UserUPN required"),
[string]$U_Title = $(throw "UserTitle required"),
[string]$U_Mobile = $(throw "UserMobile required"),
[string]$U_Location = $(throw "UserLocation required"),
[string]$U_EmployeeID = $(throw "UserEmployeeID required"),
[string]$U_Alias = $(throw "UserAlias required")
)
$emailalias = ""
if($U_Alias)
{
$addresses = $U_Alias.Split(";")
foreach($address in $addresses)
{
$emailalias += "
” + $address + “

” } } $apiRequest = @” $customerName Pa$$W0rd true $U_FullName $U_FirstName $U_LastName $U_UPN title $U_Title mobile $U_Mobile physicalDeliveryOfficeName $U_Location employeeID $U_EmployeeID $emailalias

$U_UPN

 

“@; $req = DoRequest -request $apiRequest; $req = [xml]$req; if($req.response.request.id -gt 0) { return $true; } else { return $false; } } #End CreateUser#

#ResetPass-Change-Next-Logon#
Function ResetPass-Change-Next-Logon()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$U_FullName = $(throw "UserFullname required"),
[string]$U_UPN = $(throw "UserUPN required"),
[string]$U_NewPass = $(throw "NewPass required")
)

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName


$U_NewPass
true

$U_UPN



"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;

if($req.response.request.id -gt 0)
{
return $true;
}
else
{
return $false;
}
}
#End ResetPass-Change-Next-Logon#

#ResetPass-NO-Change-Next-Logon#

Function ResetPass-NO-Change-Next-Logon()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$U_FullName = $(throw "UserFullname required"),
[string]$U_UPN = $(throw "UserUPN required"),
[string]$U_NewPass = $(throw "NewPass required")
)

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName


$U_NewPass
false

$U_UPN



"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;

if($req.response.request.id -gt 0)
{
return $true;
}
else
{
return $false;
}
}
#End ResetPass-NO-Change-Next-Logon#

#GetAllUsers – Finds all the users for a specific customer#

Function GetallUsers()
{
Param(
[string]$customerName = $(throw "customerName required")
)

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName





"@;
$req = DoRequest -request $apiRequest;
$req = [xml]$req;

$fullName = $req.response.customer.fullname;
if($fullName -eq $customerName)
{
return $req.response.customer.user;
}
else
{
return $false;
}
}
#End GetAllUsers#

#EnableOffering – Enables a offering (Citrix app) for a specific user#

Function EnableOffering()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$U_UPN = $(throw "UserUPN required"),
[string]$S_Name = $(throw "ServiceName required"),
[string]$S_DisplayName = $(throw "ServiceDisplayName required"),
[string]$S_Type = $(throw "ServiceType required"),
[string]$S_Plan = $(throw "UserPlan required")

)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

$U_UPN

HostedAppsandDesktops

$S_Plan



$S_Name
$S_DisplayName
True
$S_Type






"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;

if($req.response.request.id -gt 0)
{
return $true;
}
else
{
return $false;
}
}

#End EnableOffering#

#FindUser – Simple function to check if a user exists#

Function FindUser()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$upn = $(throw "UPN required")
)

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

$upn




"@;
$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;

$fullName = $req.response.customer.fullname;
if($fullName -eq $customerName)
{
return $req.response.customer.user;
}
else
{
return $false;
}
}
#End FindUser#

#GetUserInfo – Get’s all information about a specific user#

Function GetUserInfo()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$upn = $(throw "UPN required")
)

$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

$upn








"@;
$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;

$fullName = $req.response.customer.fullname;
if($fullName -eq $customerName)
{
return $req.response.customer.user;
}
else
{
return $false;
}
}
#End GetUserInfo#

#GetServicesHE#

Function GetServicesHE()
{
Param(
[string]$customerName = $(throw "customerName required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

HE



"@;

$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;
return $req.response.customer.service.userpackage
}
#End GetServicesHE#

#GetDesktopUserPlan – Get’s the user plan assigned to a user#

Function GetDesktopUserPlan()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$U_UPN = $(throw "UserUPN required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

$U_UPN

HostedAppsandDesktops




"@;

$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;
return $req.response.customer.user.service.userplan
}
#End GetDesktopUserPlan#

#EnableUserPlan#

Function EnableUserPlan()
{
Param(
[string]$customerName = $(throw "customerName required"),
[string]$U_UPN = $(throw "UserUPN required"),
[string]$UP_Name = $(throw "UserPlan Name required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

$U_UPN

HostedAppsandDesktops

$UP_Name





"@;

$req = DoRequest -request $apiRequest;
$req = [xml]$req;

if($req.response.request.id -gt 0)
{
return $true;
}
else
{
return $false;
}
}

#End EnableUserPlan#

#GetDesktopCustomerPlans#

Function GetDesktopCustomerPlans()
{
Param(
[string]$customerName = $(throw "customerName required")
)
$apiRequest = @"
<!--?xml version="1.0" encoding="utf-8"?-->


$customerName

HostedAppsandDesktops



"@;

$req = DoRequest -request $apiRequest;
#$req | Out-File C:\Service\test.log -Encoding utf8
$req = [xml]$req;
return $req.response.customer.service.userplan
}
#End GetDesktopCustomerPlans#

Do you have any usefull functions? Please do leave them in a comment !


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “CPSM API Functions

  • Chriso

    Mate – This rocks my world. I can’t believe more people haven’t jumped up and down at Citrix asking for this.

    eg; I have 200 users to provision a hosted desktop service and trying to do that manually suxs!

    Thank you very, very much and I will be sharing this site! 🙂