Storage PowerCLI One-Liners

From vwiki
Jump to navigation Jump to search


Get the virtual HD (VMDK) details for a particular VM

 Get-VM -Name "MyVM" | Get-HardDisk | Format-List

Get the VMDK details for a particular VM (as seen from within guest OS)

 (Get-VM -name "MyVM" | Get-VMGuest).Disks

Get the VMDK details for all VM’s in a folder (sorted by VMDK path)

 Get-VM -Location (Get-Folder -Name "MyFolder") | Get-HardDisk | sort-object -Property Filename

List VM RDMs

List VM Raw Device Mapping (RDM) disks

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

Create PowerShell drive

Create a PowerShell drive for the MyDatastore datastore

 New-PSDrive -Name DS -PSProvider ViMdatastore -Root '\' -location (Get-Datastore MyDatastore)

Upload file to datastore

Upload file to datastore (a PowerShell drive needs to be create 1st - see above)

 Copy-DatastoreItem C:\Temp\FileToUpload.vmdk -Destination DS:\VMFolder\

List LUN Multipathing

List all disk multipathing

 Get-VMHost | Get-ScsiLun | Select VMHost,Vendor,Model,LunType,CapacityMB,RuntimeName,MultipathPolicy,CanonicalName | Export-Csv lunpath.csv

Set LUN Multipathing

Set all SCSI disks to use round robin multipathing

 Get-VMHost | Get-ScsiLun -LunType disk |  Set-ScsiLun -MultipathPolicy "roundrobin"

The above came from Troy Clavell's post to be found at

Note that some SAN vendors recommend that you should also set the IOPS per path to 1 (default is 1000), there is some debate as to whether you should do this or not, HP recommend it for their SAN's, though some worry about the overhead on the ESX caused by switching paths for every IO. The choice is yours, though for further reading...