Skip to content

Archive

Category: XenServer

I installed XenServer 5.6 SP2 today in my lab.  No problems!  Looks like Citrix addressed the Realtek RTL8111/8168B issues from XenServer FP1.

Citrix Provisioning Server auto-add is a waste of time.

I use this script from a Provisioning Server that has the MCLI snapin and XenServer Powershell SDK installed. The script connects to XenServer, gets a list of virtual machines and creates target devices for the virtual machines.

#Author: Phil Lindsey
#Website: http://www.ctxfarmer.com
#Last Modified: 11/4/2010

param(
#list of xenserver(s) - comma seperated for multiple xenservers
[Parameter(Mandatory=$true)]
[string]$Xenservers,
#provisioining server collection name for the new devices
[Parameter(Mandatory=$true)]
[string]$CollectionName,
#provisioning server site name for the new devices
[Parameter(Mandatory=$true)]
[string]$SiteName,
#apply the collection's template device properties to the new devices
[boolean]$copyTemplate=$false,
#only add devices that start with a specific string
[string]$startsWith=""
)
#Add snapins
Add-PSSnapin XenServer* -ErrorAction SilentlyContinue
Add-PSSnapin MCLI* -ErrorAction SilentlyContinue

#get xenserver credentials
$creds = Get-Credential

#split up the list of xenservers
foreach($XenServer in $Xenservers.Split(",")){
  #connect to the xenserver
  Connect-XenServer -Url http://$XenServer -NoWarnCertificates -Creds $creds
  #get a list of virtual machines
  $VMs = Get-XenServer:VM | Where-Object {$_.is_a_snapshot -eq $false -and $_.is_a_template -eq $false -and $_.is_control_domain -eq $false}
  foreach($VM in $VMs){
    #get the virtual machine's name label
    $VMName = $VM.name_label
	#get the virtual interfaces for the virtual machine
    $VIFs = Get-XenServer:VM.VIFs -VM $VM
	#do not add the vm if it has more that one network interface
	if($VIFs -ne "" -and $VIFs.Count -lt 1){
	  #replace the : with - in the MAC address
	  $MAC = ($VIFs.MAC).ToString().Replace(":","-")
	  #if the user didn't define $startswith or
	  #if the user defined a $startwith value check the vm name
	  if($startsWith -eq "" -or $VMName.StartsWith($startsWith,1)){
	    #copy from the collection template?
		$VMName
		if($copyTemplate){
		  #adding the device
	      Mcli-Add Device -r `
		    siteName=$siteName,`
			collectionName=$collectionName,`
		    deviceName=$VMName,`
			deviceMac=$MAC,`
			copyTemplate=1
	    }
	    else{
		  #adding the device
	      Mcli-Add Device -r `
		    siteName=$siteName,`
		    collectionName=$collectionName,`
		    deviceName=$VMName,`
		    deviceMac=$MAC
	    }
	  }
	}
  }
  #disconnect from the xenserver
  Disconnect-Xenserver
}



Script to list the MAC addresses of virtual machines

#Author: Phil Lindsey
#Website: http://www.ctxfarmer.com
#Last Modified: 11/4/2010

param(
[Parameter(Mandatory=$true)]
[string]$Xenservers
)
$creds = Get-Credential
Add-PSSnapin XenServer* -ErrorAction SilentlyContinue
foreach($XenServer in $Xenservers.Split(",")){
  Connect-XenServer -Url http://$XenServer -NoWarnCertificates -Creds $creds
  $VMs = Get-XenServer:VM | Where-Object {$_.is_a_snapshot -eq $false -and $_.is_a_template -eq $false -and $_.is_control_domain -eq $false}
  foreach($VM in $VMs){
    $VMName = $VM.name_label
    $VIFs = Get-XenServer:VM.VIFs -VM $VM
	if($VIFs.Count -eq "" -or $VIFs.Count -gt 1){
	  foreach($VIF in $VIFs){
        $MAC = $VIF.MAC
        $VMName+","+$MAC
	  }
	}else{
      $MAC = $VIFs.MAC
      $VMName+","+$MAC
	}
  }
  Disconnect-Xenserver
}