Citrix Provisioning device creation script

This script is updated. Get the new version here: http://virtexperience.com/2012/09/04/pvs-and-xenserver-device-creation-script-version-2/

I made this script a while ago, for creating XenApp PVS devices based on vm’s running on Xenserver. The script polls XenServer for all VM’s and creates a text file. The textfile can be modified and then used for provisioning PVS devices in the PVS database, DHCP and Active Directory.

The script is very simple and does not provide much of error management so please test before use.

Copy and paste the script below, save as pvsscript.vbs. Modify variables and run:

Enter xenserver password.

Select Yes if you want a fresh VM list from xenserver, no to use previous result file.

Select Yes to see the results in a notepad window. Recommended! You may edit the list before continuing, to remove existing devices and excluded devices from list. Also, xenserver connection errors will show in the notepad window. Select no to just continue with the list unedited.

When finished editing list. Save and close notepad.

Click Yes to start PVS deployment, no to exit script.

Information about device being deployed. (Comment out this in script to reduce number of clicks, or run with cscript.exe)

IF DHCP servers is specified in the script, you will be asked to provide an IP for the device. This IP will be reserved in both DHCP servers and scope options for PVS will be added to the reservation. Note that for a redundant DHCP you should add reservations outside DHCP range, to be able to reserve the same IP on both DHCP servers.

Verify that all devices now exists in both DHCP servers, Active directory, and Provisioning Console.

Good luck!

DISCLAIMER! The use of this script is completely on your own risk. Always test before using in production!

The script:

on error resume next‘Xen/PVS deployment script
‘By Magnar Johnsen Firstpoint AS

‘Description
‘This script will list all virtual servers in a xenserver pool to a txt file for import to PVS server

‘Requierements:
‘Xenserver console installed locally
‘PVS server locally
‘DHCP role added locally if you want to deploy VM’s in DHCP. (no need to run scopes locally only the netsh tools needs the role added)
‘You will be prompted for xenserver password and ipaddress per server.
‘Please update the variables below this line
‘**********************************************************************
‘common variables
strfilename=”c:scriptmac.txt”
‘PVS variables
sitename=”Main”
collectionname=”XenAppServers”
OU=”XenAppServers”
‘if you want to reserve IP for the VM in DHCP, enter DHCP server name. Blank will skip.
dhcp1=”DHCPSRV1″
‘For redundant DHCP, enter next DHCP server.
DHCP2=”DHCPSRV2″
scope=”10.0.0.0″
pvs1=”10.0.0.11″
pvs2=”10.0.0.12″

‘Xenvariables
XENHOST=”10.0.0.10″
XENUSER=”root”

‘End of variables
‘***********************************************************************

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set wshshell = CreateObject(“Wscript.shell”)

res1=msgbox(“Do you want to read VM list from Xen now?”, vbyesno)
if res1 = vbyes then
‘query Xen, using xencenter command line tools
XENPW=inputbox(“Enter password for xen”, ”password”)
wshshell.run ”%comspec% /c ””c:Program Files (x86)CitrixXenCenterxe.exe”” -s ” & XENHOST & ” -u ” & XENUSER & ” -pw ” & XENPW & ” vif-list params=vm-name-label,MAC > ” & strfilename,0,true
End if

res2=msgbox(“Do you want to modify or verify the result now? ” & vbCrLf & ”(Opens vm list in notepad. Change list, save file and close notepad to continue)”, vbyesno)
if res2 = vbyes then
‘Open result in notepad for manual edit.
wshshell.run ”notepad.exe ” & strfilename,1,true
End if

res3=msgbox(“Do you want to deploy to PVS now?”, vbyesno)

if res3 = vbyes then
‘start PVS deployment
Set objFile = objFSO.OpenTextFile(strfilename, ForReading)
Const ForReading = 1
Do Until objFile.AtEndOfStream
server=trim(split(objFile.ReadLine,”:”)(1))
tmpmac=split(objFile.ReadLine,”:”)
mac=trim(tmpmac(1) & ”-“ & tmpmac(2) & ”-“ & tmpmac(3) & ”-“ & tmpmac(4) & ”-“ & tmpmac(5) & ”-“ & tmpmac(6))
wscript.echo ”Adding server:” & server & ” with mac:” & mac
objFile.ReadLine
objFile.ReadLine
wshshell.run ”””C:Program FilesCitrixProvisioning ServicesMCLI.exe”” Add Device /r DeviceName=” & server & ” SiteName=” & sitename & ” CollectionName=” & collectionname & ” DeviceMac=” & mac,0,true
wshshell.run ”””C:Program FilesCitrixProvisioning ServicesMCLI.exe”” Run AddDeviceToDomain /p DeviceName=” & server & ” organizationUnit =” & ou,0,true
IP=inputbox(“Enter IP for ” & server, ”DHCP reservation”, scope)
if ip <> ”” then
if dhcp1 <> ”” then
wshshell.run ”””c:WindowsSystem32netsh.exe”” dhcp server \” & dhcp1 & ” scope ” & scope & ” add reservedip ” & IP & ” ” & Replace(mac,”-“,””) & ” ” & server, 0, true
wshshell.run ”””c:WindowsSystem32netsh.exe”” dhcp server \” & dhcp1 & ” scope ” & scope & ” set reservedoptionvalue ” & IP & ” 066 STRING ” & pvs1, 0, true
wshshell.run ”””c:WindowsSystem32netsh.exe”” dhcp server \” & dhcp1 & ” scope ” & scope & ” set reservedoptionvalue ” & IP & ” 067 STRING ardbp32.bin”, 0, true
end if
if dhcp2 <> ”” then
wshshell.run ”””c:WindowsSystem32netsh.exe”” dhcp server \” & dhcp2 & ” scope ” & scope & ” add reservedip ” & IP & ” ” & Replace(mac,”-“,””) & ” ” & server, 0, true
wshshell.run ”””c:WindowsSystem32netsh.exe”” dhcp server \” & dhcp2 & ” scope ” & scope & ” set reservedoptionvalue ” & IP & ” 066 STRING ” & pvs2, 0, true
wshshell.run ”””c:WindowsSystem32netsh.exe”” dhcp server \” & dhcp2 & ” scope ” & scope & ” set reservedoptionvalue ” & IP & ” 067 STRING ardbp32.bin”, 0, true
end if
end if
Loop
objFile.Close
End if

wscript.echo ”Completed!”
wscript.quit(0)

One thought on “Citrix Provisioning device creation script

  1. Pingback: PVS and XenServer Device Creation Script Version 2 | Virtual eXperience

Leave a Reply

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

*