ESXi Powershell Commandlets: Difference between revisions

From DFWLPiki
Jump to navigation Jump to search
Line 7: Line 7:
  Connect-VIServer -Server SERVERNAME
  Connect-VIServer -Server SERVERNAME
Get all VMs that have snapshots
Get all VMs that have snapshots
  get-vm | get-snapshot | format-list vm,name,created
  Get-VM | Get-Snapshot | Format-List vm,name,created
Removing a snapshot from a specific VM
Removing a snapshot from a specific VM
  Get-Snapshot VMNAME | Remove-Snapshot
  Get-Snapshot VMNAME | Remove-Snapshot
Line 13: Line 13:
  Get-Snapshot VMNAME | Remove-Snapshot -Confirm:$false
  Get-Snapshot VMNAME | Remove-Snapshot -Confirm:$false
Check for any attached CDRom drives
Check for any attached CDRom drives
  get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}
  Get-VM | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}
Disconnect any attached CDRom drives
Disconnect any attached CDRom drives
  Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false
  Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false

Revision as of 20:50, 21 May 2018

Scope of This Document

This document covers ESXi powershell commands that I find useful

ESXi Powershell Commandlets

Connect to your vCenter

Connect-VIServer -Server SERVERNAME

Get all VMs that have snapshots

Get-VM | Get-Snapshot | Format-List vm,name,created

Removing a snapshot from a specific VM

Get-Snapshot VMNAME | Remove-Snapshot
or
Get-Snapshot VMNAME | Remove-Snapshot -Confirm:$false

Check for any attached CDRom drives

Get-VM | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}

Disconnect any attached CDRom drives

Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false

Shutting down or powering up a VM

Get-VM VMNAME | Shutdown-VMGuest
Get-VM VMNAME | Start-VM