Difference between revisions of "ESXi Powershell Commandlets"

From DFWLPiki
Jump to: navigation, search
(ESXi Powershell Commandlets)
Line 10: Line 10:
 
  get-cluster dfw-mx740c-new | Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } | Stop-VMHostService
 
  get-cluster dfw-mx740c-new | Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } | Stop-VMHostService
  
==ESXi Powershell Commandlets==
+
==Get all VMs that have RDM disks in use==
Get all VMs that have RDM disks in use
+
 
  Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName | fl
 
  Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName | fl
Find all VMs with thick provisioned drives
+
==Find all VMs with thick provisioned drives==
 
  Get-Datastore | Get-VM | Get-HardDisk | Where {$_.storageformat -eq "Thick" } | Select Parent, Name, CapacityGB, storageformat | FT -AutoSize
 
  Get-Datastore | Get-VM | Get-HardDisk | Where {$_.storageformat -eq "Thick" } | Select Parent, Name, CapacityGB, storageformat | FT -AutoSize
Find all VMs that have other than vmxnet3 network adapter.
+
==Find all VMs that have other than vmxnet3 network adapter==
 
  Get-VM | Get-NetworkAdapter | Where-object {$_.Type -ne "Vmxnet3"} | foreach ($_) {Write-Host $_.Parent.Name "("$_.Name") type:" $_.Type}
 
  Get-VM | Get-NetworkAdapter | Where-object {$_.Type -ne "Vmxnet3"} | foreach ($_) {Write-Host $_.Parent.Name "("$_.Name") type:" $_.Type}
Connect to your vCenter
+
==Connect to your vCenter==
 
  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
 
  or
 
  or
 
  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
Shutting down or powering up a VM
+
==Shutting down or powering up a VM==
 
  Get-VM VMNAME | Shutdown-VMGuest
 
  Get-VM VMNAME | Shutdown-VMGuest
 
  Get-VM VMNAME | Start-VM
 
  Get-VM VMNAME | Start-VM

Revision as of 15:24, 14 February 2020

Scope of This Document

This document covers ESXi powershell commands that I find useful

Install Powershell PowerCli Modules

Install-Module -Name VMware.PowerCLI -AllowClobber
Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCeip $false -InvalidCertificateAction Ignore

Controlling SSH service

get-cluster dfw-mx740c-new | Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } | select VMHost, Label, Running
get-cluster dfw-mx740c-new | Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } | Start-VMHostService
get-cluster dfw-mx740c-new | Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } | Stop-VMHostService

Get all VMs that have RDM disks in use

Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName | fl

Find all VMs with thick provisioned drives

Get-Datastore | Get-VM | Get-HardDisk | Where {$_.storageformat -eq "Thick" } | Select Parent, Name, CapacityGB, storageformat | FT -AutoSize

Find all VMs that have other than vmxnet3 network adapter

Get-VM | Get-NetworkAdapter | Where-object {$_.Type -ne "Vmxnet3"} | foreach ($_) {Write-Host $_.Parent.Name "("$_.Name") type:" $_.Type}

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