XenServer: Activate SDK in 64-bit PowerShell.
Not exactly new info, just putting this here so I can copy and paste instead of remembering it. :)
C:\Windows\Microsoft.NET\Framework64\<version>\InstallUtil.exe "c:\Program Files (x86)\Citrix\XenServerPSSnapIn\XenServerPSSnapIn.dll"
PowerShell: XenServer Get VM IP Address
This like all of these PowerShell XenServer examples requires you load the snapin and an active connection to a XenServer.
First you need to get a reference to your VM of choice, in this case I know the exact VM by name so I do this:
$vms = Get-XenServer:VM | Where-Object {$_.name_label -eq "<nameofVM>"}
Now I want to read the guest metrics on this VM to find the IP Address, note that this requires XSTools to be installed and the IP address wont be available right away, typically it seems to only be available after the machine has both booted, and had time for the XSTools to report it's IP to guest metrics, but once it's available you can get it by doing this:
Get-XenServer:VM_guest_metrics.Networks -VMGuestMetrics $vms.guest_metrics
Be aware that if you want to get a list of IP's for more than one VM you will need to foreach through $vms and run the command for each one.
One potential use of this is to, say, clone a new VM from a template, start it, wait for it to establish a network connection then Test-Connection until you get a result, at which time you can proceed to do whatever else you need to do (via WinRM for instance, if you have it enabled in the template).
PowerShell: XenServer Messages (Since)
If you are expecting a message to occur after an action you are taking the following may be of use to you.
$messages = Get-XenServer:Message.Since -Since [System.DateTime]::Now foreach($i in $messages.Values) { $i }
Obviously this doesn't do anything intelligent like look for the specific event, but once you see the output you can customize it to do whatever you want.
PowerShell: XenServer Recreate ISO Store
A little too much code to past directly on SquareSpace (haven't had time to figure out a way around that) but here it is.
As I've had a couple questions I figured I'd post this. Once you install the snapin you need to run the following command (most likely with admin rights), why they don't do this as part of the install I don't know, I could see there being some "security" reason.
PS C:\Windows\Microsoft.NET\Framework64\v4.0.30319> .\InstallUtil.exe 'C:\Program Files (x86)\Citrix\XenServerPSSnapIn\XenServerPSSnapIn.dll'
PowerShell: Destroy CIFS ISO Library
This is step one of two in destroying (and then re-creating) a CIFS ISO library in XenServer, the reasons you may need to do this are varied, this is personally useful to me in a lab environment when the repo location or user credentials may change often. Everythign below requires the XenServer PSSnapin.
First thing we want to do is snag the info for the SR we want to delete:
$sr = Get-XenServer:SR | Where-Object {$_.content_type -eq "iso" -and $_.type -ne "udev" -and $_.name_label -ne "XenServer Tools"}
This filters out the CD-ROM (udev) and XS Tools and just returns us SR's whose content type is ISO, so it shouldn't matter what you name your repo (um, as long as you don't name it XenServer Tools I guess).
Now we need to unplug it:
foreach($i in $sr.PBDs){Invoke-XenServer:PBD.Unplug -SR $i}
Do you need to foreach this? Probably not. But if you DO happen to set it up with multiple PBD's then it will still fail on the next step because you only unplugged some of the PBD's, when in doubt, be thorough.
Now lets remove the SR:
Invoke-XenServer:SR.Forget -SR $sr.name_label
There you go, the next step will be to ask for a path, user and password to create a new ISO Library, which I'll cover next time.
XenServer Appliance Import Fails
If you find your import sitting at "Connecting..." with a reference to the specific VDI it is trying to create at the end, 99% chance it failed to get an IP. At the last phase of the import just specify a static IP, in my case for whatever reason DHCP wasn't responding fast enough so even though it LOOKED like it was getting an IP it just wasn't making the connection. Manually setting an IP solved it.
XenServer: Add/Remove Network Interface.
Remove:
- xe vm-list
- Copy the uuid for the VM you want to remove the interface.
- xe vif-list vm-uuid=<vm-uuid>
- Copy the uuid for the vif you want to destroy.
- xe vif-destroy uuid=<vif-uuid>
Add:
- xe list-network (you can add "name-label=<label>" if you know the networks name, in my case Bond 0+1)
- Copy the networks uuid.
- xe vif-create network-uuid=<network-uuid> vm-uuid=<vm-uuid> device=#
See above for how to find the VM's uuid, for device replace # with the device number, you can find a list of supported VIF devices by typing "xe vm-param-list uuid=<vm-uuid> | more" and looking for allowed-VIF-devices, if theres no interface currently on the VM you will most likely use 0.
As for why you would want to do all of this...well, sometimes you either don't have access to XenCenter, or it decides it doesn't want to play, it's always a good idea to bring your own ball.
XenServer: Manually Set Memory Range.
xe vm-list
Grab the uuid for the VM you wish to modify.
xe vm-param-set -uuid=<uuid> -memory-static-min=1024MiB
xe vm-param-set -uuid=<uuid> -memory-dynamic-min=1024MiB
xe vm-param-set -uuid=<uuid> -memory-static-max=1024MiB
xe vm-param-set -uuid=<uuid> -memory-dynamic-max=1024MiB
You will most commonly use MiB to specify the memory size.
My most common reason for setting this is the Windows 7 template sets the minimum RAM to 2GB, which IS the recommended minimum, but obviously not needed, especially if the VM is doing primarily lightweight testing (testing an install, etc.).
XenServer: Join A Domain.
xe pool-enable-external-auth auth-type=AD service-name=<domain.com> config:user=<username> config:pass=<password>
XenServer: Add search domain to DNS.
xe pif-list host-name-label=<hostname> management=true
xe pif-param-set uuid=<uuid> other-config:domain=domain.com
reboot
hostname -d -v
Should show the search domains at the bottom.
Alternatively:
cat /etc/resolv.conf
XenServer: PXE Boot failure/solution.
So trying to boot off PXE on a XenServer VM seems to VERY frequently cause problems. I finally figured out how to work around the issue.
When booting from network (you probably need to bump network boot up above the "will not boot" line) hit Ctrl+B when it says to bring up the gPXE command line. Then do the following.
- dhcp net0 (or whatever adapter you want to use)
- config
- set "next-server" to the tftp server location (this is where all your boot images are) use the IP ot hostname.
- set "filename" to the path to the correct .com file. In my case I had to bypass the OSChooser and set the path to Boot/x64/wdsnbp.com
- Ctrl+X
- autoboot
- You should see it load the image and continue.
Note that you NEED to know the location where the images are stored and be able to see them so you know what file to point it to. If you can't figure it out, start pointing it to every .com you can find lol.
Also beware that on reboot these settings are NOT saved. Which is annoying. But hey, it beats flat out not being able to RIS.