PowerCli: Finding amount of GB used by VMs in a folder/vApp/datacenter

Sometimes it can be useful to know how much space the VMs in a specific folder (or vApp/datacenter) is occupying. For example if you are a hosting provider of some sort and need to know how much space a customer is using. It’s a simple one-liner! get-vm -Location <folder> | select name,@{Name="Size";Expression={(Get-HardDisk -VM $_.name | Measure-Object CapacityGB -sum).Sum}}

January 29, 2014 · nerenther

Powershell: Write-Progress, a step-by-step guide

For whatever reason, I had a really difficult time wrapping my head around the usage of Write-Progress. The basic usage is off-course quite easy: Write-Progress -Activity "Something" -Status "Something else" -CurrentOperation "thinking" -PercentComplete 30 This will show a quick progress bar stating that “Something” is going on, the status is “Something else” and it has gotten to 30%. However, when I wanted to use Write-Progress in a large script I quickly got confused when I looked at some of the examples out there....

January 15, 2014 · nerenther

PowerCLI: Consolidate all VMs that need consolidation

Robert van den Nieuwendijk has a nice post on how to use PowerCLI to find VMs that need consolidation and then how to start consolidation. You can that post here: http://rvdnieuwendijk.com/2012/09/26/use-powercli-to-consolidate-snapshots-in-vsphere-5/ But, as always, I prefer to make a function of these kind of things. A function is much easier to remember than a bunch of parameters and cmdlets. So here’s the code for a function that will search through the vCentre for VMs that need disk consolidation:...

November 1, 2013 · nerenther

PowerCLI: Locate a MAC-address in vCenter

To find out to which vm a MAC address belongs, you can use a simple one-liner: Get-vm | Select Name, @{N=“Network“;E={$_ | Get-networkAdapter | ? {$_.macaddress -eq“00:50:56:A4:22:F4“}}} |Where {$_.Network-ne “”} (Courtesy of this page: http://www.virtu-al.net/2009/07/07/powercli-more-one-liner-power/ ) Thats really great, and you can easily extend the one-liner to include more data if you like. But for someone who isn’t comfortable with using PowerCLI yet, it can seem a bit terrifying. Therefore I usually create functions for long one-liners like this one....

October 23, 2013 · nerenther

PowerCLI: List all vm's with ISO mounted and dismount them

Easy-peasy and a pretty short post… To get all vm’s with iso mounted: Get-VM | Get-CDDrive | select @{N="VM";E="Parent"},IsoPath | where {$_.IsoPath -ne $null} Then, to dismount those: Get-VM | Get-CDDrive | where {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$False

October 10, 2013 · nerenther

PowerCLI: Migrate all vm's on a datastore

PowerCLI is just awsome 🙂 This simple one-liner migrates all vm’s off one datastore to a new one: Get-VM -Datastore <datastore1> | Move-VM -Datastore <datastore2> You can also move vm’s off one datastore and place them in any datastore within a specified datastore cluster: $DatastoreCluster1 = Get-DatastoreCluster -Name 'DatastoreCluster1' Get-VM -Datastore <datastore1> | Move-VM -Datastore $DatastoreCluster1

October 8, 2013 · nerenther

PowerCLI: List all snapshots

It’s been a while since last update, again, so I figured I should at least provide something.. I recently started in a new job, and one of the first things I looked into was the amount of snapshots in our vmware environments. Not surprisingly there was a lot of snapshots, and very few of them had any hints of when they were taken and why. The vsphere console doesn’t provide this info so I had to turn to PowerCLI to get the info I needed....

October 3, 2013 · nerenther

Powershell: Invoke-Sound function

I stumbled upon this brilliant powershell function for playing sounds using powershell, check it out: http://community.spiceworks.com/scripts/show/1337-powershell-function-invoke-sound He even added a switch for playing the imperial march from Star Wars 🙂

April 18, 2013 · nerenther

Powershell: Install role or feature on multiple remote servers

Today I was presented with a task that sounded pretty boring and repetitive: Install the Windows Search service on all our citrix servers. Now, I could just log on each and every one of our citrix servers, open Server Manager and then install the role service but where’s the fun in that? As always Powershell is a lot more fun: First I had to find the name of all our citrix servers....

March 26, 2013 · nerenther

Powershell: Export-Csv and non-English letters

The Export-Csv cmdlet is a really nice tool if you want to gather info from e.g. Active Directory that you later want to import to Excel. But as you might have noticed it doesn’t play well with non-English letters. Working in Norway with users from all the Nordic countries means that we have a lot of users i Active Directory who have non-English letters in their names (æ ø å ö ä and so on)....

January 17, 2013 · nerenther