PowerShell Script: Decommision VDI (XenDesktop & vCentre)

I have been trying to learn PowerShell and this is my first attempt at a script that just works. This PowerShell script will put a XenDesktop VDI into maintenance mode, disable the object in Active Directory and shutdown the VM in vCentre as well as moving between containers (if required). This is handy if you have a lot of VDIs that need to decommissioned.

See below for the script, you will need to ensure a list of names are in a CSV called IMPORT_DecomissionVDI.csv. The reason for the ‘IMPORT’ is I find it easier to keep track of what a CSV does, so ‘EXPORT’ / ‘IMPORT’ etc. The same goes for the PowerShell script files ‘Set’ if it’s going to change something and ‘Get’ if it’s going to return information. Handy so you don’t run the wrong script!!

An example of what the CSV should look like:

PS-VDIName

Don’t forget to change the variables at the start.

#========================================================================
# File: Set-DecommisionVDI.ps1
#
# Description: This script imports a list of VDIs to be disabled, sets the VDI in XenDesktop in maintenance mode, then disables the AD account 
# and moves to an OU if required. Lastly the script moves the VDI in vCentre if required and shuts down the VDI.
#
# Date: 12/09/14 11.52 PM
# Author: Chris Stark
# Version 0.1
# Blog: ChrisStark.co
# Twitter: twitter.com/ChrisLStark
# Google+: http://google.com/+ChrisStark86
# LinkedIn: http://www.linkedin.com/profile/view?id=clstarks
# Link: http://chrisstark.co/2014/09/powershell-script-decommision-vdi-xendesktop-vcentre/
#========================================================================

# Imports Citrix and VMware PowerShell snapins

Add-PSSnapin Citrix.*
Add-PSSnapin VMware.VimAutomation.Core

# Variables for Citrix XenDesktop Server, vCentre, Domain and paths to move VDIs

$Domain = ' '
$XenDesktop = ' '
$VCentre = ' '
$CSVFile = 'IMPORT_DisableVDIs.csv'
$DisableADPath = 'OU=Disabled Computer Accounts,DC=DOAMIN,DC=co,DC=uk'
$VcentreFolder = "Disabled VDIs"

# Connects to the Citrix XenDesktop server

Get-BrokerSite -AdminAddress $XenDesktop

# Connects to VMware vCentre

Connect-VIServer $VCentre

# Imports the list of computers to disable

$CSV = import-csv $CSVFile

# Loops through the VDIs

foreach ($Item in $CSV)
{
# Sets the variable VDIName to the name of the VDI being disabled

 $VDIName = $Domain+$Item.VDIName

# Sets the VDI to maintenance mode 

 Get-BrokerDesktop -MachineName $VDIName | Set-BrokerPrivateDesktop -InMaintenanceMode $true

# Disables the AD account of the VDI

 Get-ADComputer $VDIName | Set-ADComputer -Enabled $false

# Moves the VDI to the disabled OU - remove line if not required

 Get-ADComputer $VDIName | Move-ADObject -TargetPath $DisableADPath

# Moves the VM to the Disabled VDIs folder - remove line if not required

 Move-VM -VM $VDIName -Destination $VcentreFolder

# Shuts down the VDI

 Get-VM $VDIName | Shutdown-VMGuest -Confirm:$false
}

Download here

Citrix XenDesktop + Default printers not sticking

I had an issue whereby default printers were not sticking. Every time a user set a default printer and then re-logged in the printer would revert back.

Took me a while to find the cause, as I was either RDPing or using the vSphere client to troubleshoot and not via the Citrix client.

Turns out, there’s a policy (bear in mind I’m new to Citrix) that allows Citrix XenDesktop to control default printers. Turned this off, and BOOM! the default printers stayed.

To change the policy, open Desktop Studio.

Navigate to the users policy:

XenPrinter1

Within the Users policies you will see the policies you’ve. In this example mine is called “Unfiltered” select this and then Edit.

XenPrinter2

Click on settings and then scroll to “Printing” on the right next to Default printer click add.XenPrinter4Here is the default policy:

XenPrinter6

We don’t want Citrix to change the printer therefore change to “Do not adjust the users default printer”.

XenPrinter7

Click ok. Citrix will let you know its updating the policy.

XenPrinter8

You can double check the policy is applied by editing and verifying it has been added.

XenPrinter9

Success!

HP MicroServer N36L replacement power supply (PSU)

Came home to find the HP MicroServer was powered down last week and panicked! Turns out on further testing the power supply had decided to pack up. Not bad for 2 and a half years, running as a lab environment, 6 HDDs, PCI-E HD Graphics card and running as home entertainment system! As you can imagine, getting the PSU or ordering a replacement server was high priority. Though seeing as the HP MicroServer cashback offer has stopped led me to source a PSU.

Seeing as these MicroServer are popular as HTPC, storage, virtual environments for labbing etc, I gathered others may benefit from this post.

Now, finding a replacement wasn’t easy or looking to be cheap. The official HP part number 620827-001 was showing about £98.57 on the HP parts store – ouch!

So, after much research I come across the site LinITX which sell 1U PSUs and cheap. I first come across this when reading others were using a PicoPSU and a power brick – this seemed to pricey for me £50+ though does offer less noise.

I emailed the guys over at LinITX as I was worried about fitting etc and wanted to be reassured I could send back if any problems, yes I could’ve sent back under the distance selling regulation act but couldn’t be dealing with the hassle, much politer to just ask. Thumbs up to LinITX.

I opted for the FSP 150W 1U Compact Power Supply – FSP150-50GUB which as of this blog post is £27 + P&P – comes to about £30.96 – I selected normal royal mail and received the next day! does say up to 2 days.

The PSU fitted without any issues and the 24 pin connector easily fits, the SATA parts can be a stretch if using additional hard-drives in the top bay, though if required you could extend these. Mine just about fit.

You will need to buy an adapter to convert the SATA power to Molex for the drive bay as the one molex provided isn’t enough, I went for for a molex 4-way splitter. I bought mine from Maplin as I wasn’t sure on cable length.

The PSU is nosier than the HP one, but if you want a cheap solution and don’t want to go down the PicoPSU route this will do fine.

Overall, a cheap good alternative! This should work for other models such as the N40L.

A pic of the PSU and adapter, excuse the poor quality – I had both replacement PSU and Nexus 7 (2013) turn up so was in a rush to play with the new toy!CameraZOOM-20130828195021637

CameraZOOM-20130828195034551[wp_ad_camp_1]

Cisco ICND2 – Passed – Now a CCNA

This morning I took and passed the Cisco ICND2 on the second attempt. I felt it was a little harder than ICND1 and in some ways I was a little unprepared the first time due to changing jobs / Open University commitments. Having previously done the course via the Open University a few years ago and got a little complacent, despite the blog posts.

Any tips for taking the exam? read the question and re-read. I think i made this mistake on the first attempt, though I doubt that would’ve made much of a difference, however it could make the difference between a pass and a fail.

All the resources I used can be found here.

If your taking the exam before the end of next month, best of luck! 🙂

What’s next for me? I’m thinking either Server 2012 or Citrix… though favoring Citrix at the moment.

Trend Deep Security – Anti-Malware Engine Offline – vSphere Environment

So been trying to troubleshoot the above error “Anti-Malware Engine Offline” and been having a hard time doing so. I have experienced three different things causing this; vShield drivers missing, incorrect DNS and virtual machines going to sleep/standby.

 The error will flag up within deep security as:

Anti-Malware Engine Offline

With the details as “The Anti-Malware Engine is not responding. Please ensure that it has been installed correctly”.

Anti-Malware error details

A few things to check:

  1. First ensure the DSVA is running and is sitting on the correct host as the virtual machine.
  2. Ensure vShield drivers are installed correctly on the virtual machine – see my post here.
  3. Check DNS is correct on the virtual machine and it can see the DSVA and trend management console.
  4. If the virtual machines goes into sleep mode/standby, this may flag the error up.

How to check and install vShield drivers on a Virtual Machine

This post will show you how to check to see if the vShield drivers are installed and if not how to install them via VMware Tools. You may be using an anti-virus software such as Trend Deep Security whereby its throwing up anti-malware engine offline errors which could be linked to the vShield drivers missing.

  1. First thing is to log onto the virtual machine and open up msinfo32 via the run prompt (start > run > msinfo32).
  2. Expand “Software Environment” and then “System Drivers”
  3. Within this list you’re looking for vsepfit as shown below:

vsepfit

If you see the driver listed, then vShield is installed. if not, continue on with this post.

First ensure VMware Tools is installed, it could be as simple as you forgot to install the tools. If not, then vShield may have been implemented after some VMs were created or something odd has happened. Follow the next steps to add the vShield drivers to existing VMware tools.

Locate the VM within vSphere and right-click Guest>Install/Upgrade VMware Tools.VMToolsUpgrade1

Select Interactive Tools upgrade.
VMToolsUpgrade2

Go to the console of the VM and you should see the installation wizard. Click Next.

VMToolsUpgrade3

Ensure Modify is selected. Click Next.

VMToolsUpgrade4

Expand VMware Device Drivers. Click Next.

VMToolsUpgrade5

Expand VMCI Driver, click the drop down on vShield Drivers and select “This feature will be installed on local hard drive”.VMToolsUpgrade6

Now the vShield Drivers should look like the following. Click Next.

VMToolsUpgrade7

VMware Tools is now ready to begin installation. Click Modify.

VMToolsUpgrade8

Installing…

VMToolsUpgrade9

and we’re done! Click finish.

VMToolsUpgrade10

You will be asked to restart. Assuming now is a good time, click yes.

VMToolsUpgrade11

That’s the vShield drivers installed.

ESXi5 Datastore error – Expected put message. Got: ERROR

When trying to download a VMX file via the datastore browser, I was presented with the following error “Expected put message. Got: ERROR” as shown below:Expected Put Message. Got Error

This had be stumped for a moment as i have never encountered this before. The following knowledge base by VMware explains this behaviour and how to overcome.

Luckily I was in the position to power of the virtual machine and download the VMX file and power back on. Though when I tried again with the virtual machine powered back on, same issue occurred.

I did find when vMotioning between hosts (same datastore) I could then download the VMX file with the virtual machine still on.

I have read that similar people have had issues with brackets in the virtual machine name (wasn’t the case here) that can get confused with the datastores (as brackets define datastores). Might be worth watching out for this one.

This was using VMware ESXi 5.0.0 768111.