Powershell: Fix Orphaned Standby hosts after vCenter reboot!

vCenter’s Distributed Resource Scheduler (DRS) is by far one of my favorite features of VI2.5.  Distributed Power Management (DPM) is an experimental extension of DRS that will power down unneeded hosts, and wake them when needed again.  How cool it that!  The good news is, it works great.  The bad news is, in the current release there is a bit of a bug in DPM.

When vCenter is restarted it looses track of any hosts that it (DPM), or you (the VI admin) have put in a suspended state.  The suspended hosts show up in VC as “NotResponding”, and VC is no longer capable of waking them up.  The fix is to manually power them on… how aggravating.  I finally had some free time this morning so I threw together a quick PowerShell script to bridge the gap until VMware releases a production ready version of DPM.

Read morePowershell: Fix Orphaned Standby hosts after vCenter reboot!

PowerShell oneliner: Change the VMotion vNic

I tried for over an hour to use the Set-VMHostNetworkAdapter for the life of me I can’t get it to work. Fortunately the SDK is both well documented and wide open thanks to the get-view cmdlet!

that’s it… Now the cool thing here is that let’s say vnic vmk1 is currently selected. The SelectVnic method will unselected vmk1, and select vmk0. As with everything in the VI toolkit once you figure out how to do one, scale is suddenly a trivial task.

Personally, I always test automation task like this on a ‘test cluster’.

If you haven’t figured it out yet… We’re making a concerted effort to solve any issue we find. From both the view point of a Windows (PowerShell) and a *nix(perl) administrator’s point of view. All of this stuff is really just a stop gap until the RCLI has matured. We’ll at least the perl is (have you seen how long that stuff is :))

Adjusting Console OS RAM via Powershell

You know after Andrew does all the hard work in perl… Converting this stuff to powershell is like shooting fish in a barrel.

Get the current COS Ram configuration:

Change the ammount of RAM dedicated to the COS to 512MB:

~Glenn

Provisioning server for VM’s

Andrew and I recently reorganized our VI at work.  One of the key changes was the concept of datacenters via function… Without getting to far into it. One of the functions we identified, a stand alone resource pool to deploy all VM’s from.   We’re referring to it as our provisioning cluster.  Basically whenever we get a request for a new VM.  The VM is deployed there and then VMotioned to it’s appropriate resource pool only after everything is verified, and documented.

Well done with the theory.  I started to organize all our templates through VIC, but quickly relied we have a ton of them!  Win2k, Win2k3, Win2k8, RELH4, Solaris 10… all or which have x86/x64 variants for each of our licensed options… Standard, Enterprise, Datacenter… etc.  Did I mention all I did for a month was build templates.  Anyways they where everywhere, and I was not looking forward to this.  Then I read this post From Hal’s blog, and quickly realized that with was something worth scripting.  The version I used at work looked like

Get-Template | get-view | % {$_.MarkAsVirtualMachine((get-cluster "pool1" | Get-ResourcePool | get-view).MoRef, (get-VMHost "ESX1.localdomain.local" | get-view).MoRef); $_.MarkAsTemplate()}

but that kids is not what I would call production ready.  That’s what I love about PowerShell I had a one time task… boom one line!  Took 15 min to find/move all of the templates we had in our env.   As I was added this script to our internal Wiki it occured to me someone could probably build on this the same way I built on Hal’s post.  So here is a slightly more polished version.

~Glenn

Simplify Get-VIServer

BSonPOSH took almost all the pain out of logging into Virtual Infrastructure with his get-credentials script.  That was still too much typing for me.  Every time I turned around I had timeout of my VC session.  My solution a small function added to my profile.

################### Start VMWARE ##################################

# Load Admin credentials
# Modified from http://bsonposh.com/archives/338

$creds = New-Object System.Management.Automation.PsCredential(“DomainUser-adm”, `
(Get-Content “$env:homesharescriptsmycreds.txt” | ConvertTo-SecureString)

# Load Vmware

IF (!(Get-PSSnapin | ?{$_.name -eq “VMware.VimAutomation.Core”}
{
Add-PSSnapin VMware.VimAutomation.Core
}

# Add VMware Community Extentions
# Requires Powershell V2
Add-Module “$env:homesharescriptsVMWareExtenstions.psm1”

Function Get-VC([string]$VCServer = “DefaultVCServer”)
{
Get-VIServer -Server $VCServer -Credentials $creds | Out-Null
}

Set-Alias GVC Get-VC

################### End VMWARE ####################################

Now when I want to connect to my primary VC Server I type.

PS > . GVC
that’s dot space GCV…

NOTE:  As far as how secure is this solution?  Well, my password is stored in a file.  That file cannot be interpreted by anyone other then me (similar to EFS).  Additionally I know some would mock globally loading $creds. However, I work on an isolated network, and my execution policy is set to ALLSigned.  I acknowledge that there is still a risk, but it’s one I can live with.

~Glenn

UPDATE:  VMware has changed the get-viserver cmdlet to connect-viserver more to come…