Tag Archives: get-vm

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. A basic function doing the same thing can look something like this: function Get-MACAddress ($MAC) { Get-vm | Select Name,Folder,PowerState, @{N=”Network”;E={$_ | Get-networkAdapter | ? {$_.macaddress -eq $MAC}}} | Where {$_.Network-ne “”} } That way, it enough to type Get-MACAddress 00:50:56:A1:50:43 Or, you can take the time to create a proper function: function Get-MACAddress { [CmdletBinding()] Param ( [parameter(Mandatory=$True,ValueFromPipeline=$True)][Validatelength(17,17)][string]$MAC, [string]$Location = ‘*’ ) Get-VM -Location $Location | Select Name,Folder,PowerState, @{N=”Network”;E={$_ | Get-networkAdapter…

Read more

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

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

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. PowerCLI is really just a snap-in to powershell so I felt right at home 🙂 After you start PowerCLI, you need to first connect to your vcenter server: Connect-VIServer <vcenter server> You will be promted for username and password for vcenter. After powershell has connected to the vcenter server, all you need to is run this one-liner: Get-VM | Get-Snapshot | Select VM,Name,@{N=”SizeGB”;E={@([math]::Round($_.SizeGB))}},Created This will…

Read more