Create new Citrix Provisioning target devices, including VMware VM’s, DHCP reservation and AD accounts from a CSV file with PowerShell

As you may know my motto is; Automate Everything. So when a costumer asked me to create almost 100 Citrix Provisioning Services Target Devices with a correlation between MAC and IP address I thought to myself;  let’s create a PowerShell script!’

The goal of the script:

  • Read data from a CSV file (see sample file) with the Hostname, IP Production network, MAC Production network, IP PVS Network, MAC PVS Network and Device collection.
  • Create new target devices in device collection in Citrix Provisioning Services
  • Create AD machine accounts
  • Create DHCP reservation in the PVS LAN
  • Replicate the DHCP reservation to second DHCP Server in PVS LAN
  • Create DHCP reservation in the Production LAN
  • Replicate the DHCP reservation to second DHCP Server in Production LAN
  • Create VM in VMware from Template Device
  • Set the MAC address of the new VM Production Network adapter
  • Set the MAC address of the new VM PVS Network adapter

The script is designed to work in an environment with VMware and where PVS and Production LAN are separated. If this is not the case you can of course edit the script to your liking! And if you have any problems editing the script you can always contact me.

Download Example CSV:


This is the first part of the script and must be ran on the PVS Server.

This is the second part of the script and must be ran on a server with VMware PowerCLI installed. Download PowerCLI here.

I hope this was informative. For questions or comments you can always give a reaction in the comment section or contact me:

7 thoughts on “Create new Citrix Provisioning target devices, including VMware VM’s, DHCP reservation and AD accounts from a CSV file with PowerShell

  1. Awesome Chris! Thanks for that.
    Any Idea how I could create the vms on xenserver including the mac addresses?

    Could I use your example:

    $VMname = “VMNAME”
    $StorageRepositoryName = “Local Storage”

    Invoke-XenVM -Name “Windows Server 2016 (64-bit)” -XenAction Clone -NewName $VMname
    $newvmspecs = Get-XenVM -name $VMname
    $sr = Get-XenSR -Name $StorageRepositoryName
    $other_config = $newvmspecs.other_config
    $other_config[“disks”] = $other_config[“disks”].Replace(‘sr=””‘, ‘sr=”{0}”‘ -f $sr.uuid)

    Set-XenVM -Name $VMname -OtherConfig $other_config

    Invoke-XenVM -Name $VMname -XenAction Provision

    And try to pass the info using $other_config?
    Or is it true that I would need to delete the “vif” config for the newly created VM and recreate it for the 2 interfaces?

    Thanks for your help!

    1. Good question, and I’m really sorry but I’m not able to help with it now. My XenServer lab is down. Busy with VMware. Would be fun to figure that one out please keep me posted if you do and I will try and find time to do so as well.

      1. Hi Chris, I think i found a suitable solution (for me). Just make sure your template does not have any networks attached. Then you can simply create them using New-XenVIF

        #####Define Parameter – Or take them from csv######
        $VMname = “TestVM”
        $StorageRepositoryName = “Local Storage”
        $NETLAN = Get-XenNetwork -Name “VM VLAN Bond 1+4”
        $NETPVS = Get-XenNetwork -Name “PVS VLAN Bond 0+3”

        ##### create vm from template ######
        Invoke-XenVM -Name “YOURTEMPLATE” -XenAction Clone -NewName $VMname
        $newvmspecs = Get-XenVM -name $VMname
        $sr = Get-XenSR -Name $StorageRepositoryName
        $other_config = $newvmspecs.other_config
        $other_config[“disks”] = $other_config[“disks”].Replace(‘sr=””‘, ‘sr=”{0}”‘ -f $sr.uuid)
        Set-XenVM -Name $VMname -OtherConfig $other_config
        Invoke-XenVM -Name $VMname -XenAction Provision

        ##### add the network adabters ########
        $vm_ref=Get-XenVM -Name $VMname | Select-Object -ExpandProperty opaque_ref
        New-XenVIF -VM $vm_ref -Network $NETPVS -MAC “11:22:33:44:55:66” -Device 0
        $vm_ref=Get-XenVM -Name $VMname | Select-Object -ExpandProperty opaque_ref
        New-XenVIF -VM $vm_ref -Network $NETLAN -MAC “11:22:33:44:55:66” -Device 1

        I think you need to run the $vm_ref=GetXenVM …. twice, otherwise it will not recognize the existing opaque_ref properties from the first adapter you added.

        Hope that helps!

        Ben

Leave a Reply

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