Posts tagged: one liners

One Liners, We All Love Them

CD-Rom
Finds all the vm's with a cd-rom connected and disconnects them

[powershell]
Get-VM | Where-Object {$_ | Get-CDDrive | Where-Object { $_.ConnectionState.Connected -eq "true" } } | Get-CDDrive | Set-CDDrive -Connected $false -Confirm:$false[/powershell]

Mark the vm's starting with zT as a template*
[powershell]
foreach ($d in (get-vm zT*)){$vm2 = Get-VM $d | Get-View; $vm2.MarkAsTemplate()}
[/powershell]

Deletes all Snapshots over 2 days old
[powershell]foreach ($snap in (Get-VM | get-snapshot)){if ($snap.Created -lt (Get-Date).AddDays(-2)){Remove-Snapshot $snap -Confirm:false}}[/powershell]

Connects all VM's with a certain name to the same iso

[powershell]
get-datacenter dc | get-cluster cl | get-vm 2008* | get-cddrive | set-cddrive -IsoPath "[Datastore Name] -isoname.iso" -Connected:$true -Confirm:$false[/powershell]

Let's Find the HAL level for vm's

[powershell]
Get-VM |Where {$_.PowerState -eq “PoweredOn“} |Sort Name |Select Name, NumCPU, @{N=“OSHAL“;E={(Get-WmiObject -ComputerName $_.Name-Query “SELECT * FROM Win32_PnPEntity where ClassGuid = ‘{4D36E966-E325-11CE-BFC1-08002BE10318}’“ |Select Name).Name}}, @{N=“OperatingSystem“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select Caption).Caption}}, @{N=“ServicePack“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select CSDVersion).CSDVersion}}
[/powershell]

VMHost
Disable vMotion All the host in a cluster

[powershell]
get-datacenter DC | get-cluster CL | get-vmhost | set-vmhostadvancedconfiguration -Name Migrate.Enabled -Value 0
[/powershell]

WordPress Themes