Citrix Provisioning Server with PowerShell

###########################################################################
#
#
NAME: Citrix_PVS_With_PowerShell
#
#
AUTHOR: SivaMulpuru
#
#
COMMENT: automate advanced citrix pvs tasks
#
can be used in disaster recovery situations to quickly bring up the infrastructure
#
#
VERSION HISTORY:
#
1.0 6/27/2011 – Initial release
#
#
##########################################################################

$devicename = child01
$MACRegEx = ([0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2})
$Domain = MULPURU.LOCAL
$OU = Computers/PVSMachines
$TargetDevice = mcli-get deviceinfo -p devicename=$devicename -f devicemac,adTimestamp
# Checking for existing target device
# mcli-get deviceinfo returns an array of strings, the 4 array entry contains the Number of records found
# Example: – Record #1, hence we use it with -match to find out its existence
if($TargetDevice[3] -match 1)
{
$devicename target device already exists.
if($TargetDevice[4] -match $MACRegEx)
{
$MAC1 = $Matches[1]
$devicename has the $MAC1 as MACAddress
#can be used to create a VM using this MACAddress

}
#adTimestamp contains the time the Active Directory machine account password as generated. Default=0
#we can use this to find out if the machine account is created
#Example: – adTimestamp: 1308685816
#to get the timestamp we split the string with “:”, get the second array value and trim out the empty spaces
if($TargetDevice[5].split(:)[1].Trim() -eq 0)
{
mcli-Run AddDeviceToDomain -p deviceName
=$devicename, domain=$Domain , organizationUnit=$OU
if(!$?)
{
PVS target device $devicename adding to domain failed.
continue
}
Target Device $devicename successfully added to domain and placed under $OU.
}
else
{
Target Device $devicename Computer Object already exists.
}
}

Leave a comment

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

WordPress Appliance - Powered by TurnKey Linux