http://www.citrix.com/go/citrix-developer/xenapp-xendesktop-developer-community/power-shell-xenapp7.html
For Xenapp 6.5
http://www.citrix.com/downloads/xenapp/sdks/powershell-sdk.html
Remember, if you have more than one runbook server, you’ll need to install it on all of them.
First here is the overview of our Runbook.
As always when doing Request Offerings from Service Manager into Orchestrator, we need a variable that is linked into the Request Template in Service Manager so that Orchestrator can get all the related information from the Service Manager Service Request. In my case I almost always just call it RBAID.
First I want to get the Related User to the Runbook, for the Object GUID we use the RBAID.
Then we get the user in Service Manager by subscribing to the Related Object GUID from the get Related User Activity.
Next we get the Service Request via the relationship to the Runbook Automation Activity, we do this by subscribing to the Object GUID from Get Runbook Activity.
And now we get the actual Service Request by subscribing to the Related Object GUID from Get Related Service Request.
As you recall from my previous Citrix post, I use subscribed variables for the username and password.
$RunAsAccount = “subscribed variable citrixaccount”
$RunAsPass = “subscribed variable citrixaccountPW”
We then convert the encrypted password to a string.
$pass = $RunAsPass | ConvertTo-SecureString -AsPlainText -Force
Now we create our credentials for the remote session we are about to enter.
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $RunAsAccount, $pass
We then create our session to our Citrix Server
$session = New-PSSession -computername citrixserver -Credential $credentials
And now our command
invoke-command -session $session -scriptblock {
add-pssnapin citrix*
Get-xasession | where { ($_.accountname -eq “subscribed.Domainsubscribed.UserName”)} | stop-xasession
}
remove-pssession $session
After some cleanup we update the Service Request depending on success or failure. I will say the failure is limited because we are doing remoting, in this case the only failure is if Orchestrator could not successfully run the command against the server. It does not account for if it was unable to find the correct user.
This runbook is provided as an example and is not production ready, please test in your own environment. The runbook is provided as is and without warranty.
The runbook can be downloaded from here