Posts Tagged ‘ laez

PowerCLI: Reset CD-drives using PowerShell

As most of you know and probably experienced from time to time: when a Virtual Machine’s CD-drive is connected to an ISO-file on one of your Datastores or even connected to the physical drive of your ESX-host the migration due VMotion of a Virtual Machine will not work.

Normally this isn’t really a problem except if you put a ESX-host in Maintenance mode and Virtual Center will simply not tell you why the Maintenance mode process is hanging or even giving a time-out after 15 minutes for no obvious reason. Most of the times it’s a Virtual Machine which has a CD-drive connected to an ISO file. A waste of time if you ask me.

So to prevent this from happening I’ve written a simple PowerShell oneliner/script disconnect these CD-drives from the ISO-files or from the physical drives and set them to Client-drives which is ok for VMotion:

(Get-VM -Location :( Get-VMHost "your.esx.host")) | `
ForEach ( $_ ) { Get-CDDrive $_ | `
Where { $_.IsoPath.Length -gt 0 -OR $_.HostDevice.Length -gt 0 } | `
Set-CDDrive -NoMedia -Confirm:$False }

Instead of executing this just on one host you can also execute this for your entire cluster:

(Get-VM -Location :( Get-Cluster "Your Cluster Name")) | `
ForEach ( $_ ) { Get-CDDrive $_ | `
Where { $_.IsoPath.Length -gt 0 -OR $_.HostDevice.Length -gt 0 } | `
Set-CDDrive -NoMedia -Confirm:$False }

Or ofcourse, by Datacenter:

(Get-VM -Location :( Get-Datacenter "Your Datacenter Name")) | `
ForEach ( $_ ) { Get-CDDrive $_ | `
Where { $_.IsoPath.Length -gt 0 -OR $_.HostDevice.Length -gt 0 } | `
Set-CDDrive -NoMedia -Confirm:$False }

It’s as easy as that, now there will be no Virtual Machine interrupting your VMotions anymore and you can put your ESX hosts in maintenance mode without any problems ;)

Cheers!

PowerGUI Script Editor – Empty Your Runspace

Here’s a useful tip for anyone who enjoys the handy debugger in the PowerGUI Script Editor during their intensive PowerShell scripting activities ;)

Variables

The most useful feature while debugging is the “Variables” window in the editor.

It allows you to see all the variables/objects that you declared and look inside them to see what data they contain.

 

 

 

The only problem is if you work in a script, making a lot of changes in the process, the Variables window will keep on filling up with all the variables that are used in the scripts even though some variables are not even used anymore.

This causes a mess in the Variables window so you kind of lose track of the things that actually matter and are worth keeping an eye on. So, I went looking in the Options (menu Tools > Options) and I found an option that resets the debug/variables windows (Runspace) every time you start a new debugging session. 
 
imageSimply select the “Reset PowerShell runspace each time debugging is started.” option, press OK and you will have a nice and tidy runspace (variables/debug window) from now on.

Visual Studio 2010 Beta 1

Hi Everyone!

Welcome to my first blog post on my own blog page. This finally gives me the opportunity to write a bit more and add a bit more imagery than I can do on just Twitter. Now that being said, let’s get to where this post is about :)

Microsoft finally release the first Beta of Visual Studio 2010. Now I’m not a fulltime developer, but I enjoy to develop a thing or two every now and then. Besides that I really love to see what’s new in new versions.
So I downloaded the ISO-image from Microsoft’s MSDN and I started instaling it on my Windows 7 RC installation. The installation is no other than 2008 except the only difference is that it starts installing the Beta version of the .NET 4.0 Framework which I suppose should offer a bit more features than 3.5 did.

After the installation -and the inevitable reboot- I ran Visual Studio 2010 and configured the environment for Visual C# usage, simply because that’s the language I’ll be developing in ;)

visual-studio-splash

Read more