Friday, 7 August 2015
PowerCLI - VM manipulation
How to get vCPU count of all powered on VMs of particular ESX host
Get-VMHost -Name HostName | get-vm | Where {$_.PowerState -eq "PoweredOn"} | Measure-Object -Property NumCpu -Sum | select -ExpandProperty Sum
How to get count of all powered on VMs of particular ESX host
$a = Get-VMHost -Name HostName | get-vm | Where {$_.PowerState -eq "PoweredOn"} | select NumCpu; $a.count
How to get summary of VM snapshot size
$vms = get-vm; foreach ($vm in $vms) {$snap = get-vm -Name $vm.Name | Get-Snapshot | Measure-Object -Property SizeGB -Sum | Select Name -ExpandProperty Sum; if ($snap -gt 0) {$vm.Name, $snap}}
Get Canonical Name and Capacity of all Raw Devices (RDM) attached to each VM in the cluster
foreach ($v in $(get-cluster -Name Cluster Name | Get-VM)) {$v.Name; Get-VM -Name $v.Name | Get-HardDisk -DiskType RawPhysical | select ScsiCanonicalName,CapacityGB}
Thursday, 6 August 2015
PowerCLI - Datastore manipulation
Get all LUNs connected to host
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun
Get all "disk" LUNs connected to host
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk
Get alldatastores name, free space, capacity
Get-View -ViewType Datastore -Property Name, Info | Get-VIObjectByVIView
Set MultiPath Policy to "RoundRobin" on all LUNs which have not "RoundRobin" already
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk | Where {$_.MultiPathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultiPathPolicy "RoundRobin"
Get full information of all LUNs connected to host (you can find here SAN device Model which will be used in next command)
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun | fl
Set MultiPath Policy to "RoundRobin" on all LUNs where SAN model is "VRAID"
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk | Where {$_.MultiPathPolicy -ne "RoundRobin" -and $_.Model -eq "VRAID"} | Set-ScsiLun -MultiPathPolicy "RoundRobin"
Get Canonical Name ans Capacity of all LUNs attached to each host in the cluster
foreach ($v in $(get-cluster -Name ClusterName | Get-VMHost)) {$v.name; Get-VMHost -name $v.Name | Get-ScsiLun | select CanonicalName,CapacityGB}
Get Canonical Name and Prefered Path of all LUNs connected to host where Path Policy is set to "Fixed" and SAN model is not "VRAID"
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk | Where {$_.MultiPathPolicy -eq "Fixed" -and $_.Model -ne "VRAID"} | Get-ScsiLunPath | select ScsiCanonicalName, Name | Export-Csv -NoTypeInformation -UseCulture -Path c:\test\zone1_path.csv
Get all Equallogic datastore path policy and iop to switch path
Get-VMHost | Get-ScsiLun | Where {$_.Vendor -eq "EQLOGIC"} | select VMHost, MultipathPolicy, CommandsToSwitchPath
Get all Equallogic datastore path policy to "RoundRobin" and iop to switch path to "3"
Get-VMHost | Get-ScsiLun | Where {$_.Vendor -eq "EQLOGIC"} | Set-ScsiLun -MultipathPolicy RoundRobin -CommandsToSwitchPath 3
Display all datastores attached to ESX hosts with their Canonical Names
get-vmhost -Name HostName | Get-Datastore | Where-Object {$_.ExtensionData.Info.GetType().Name -eq "VmfsDatastoreInfo"} | ForEach-Object { if ($_) {$Datastore = $_; $Datastore.ExtensionData.Info.Vmfs.Extent | Select-Object -Property @{Name="Name";Expression={$Datastore.Name}},DiskName}}
Get all LUNs connected to host
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun
Get all "disk" LUNs connected to host
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk
Get alldatastores name, free space, capacity
Get-View -ViewType Datastore -Property Name, Info | Get-VIObjectByVIView
Set MultiPath Policy to "RoundRobin" on all LUNs which have not "RoundRobin" already
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk | Where {$_.MultiPathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultiPathPolicy "RoundRobin"
Get full information of all LUNs connected to host (you can find here SAN device Model which will be used in next command)
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun | fl
Set MultiPath Policy to "RoundRobin" on all LUNs where SAN model is "VRAID"
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk | Where {$_.MultiPathPolicy -ne "RoundRobin" -and $_.Model -eq "VRAID"} | Set-ScsiLun -MultiPathPolicy "RoundRobin"
Get Canonical Name ans Capacity of all LUNs attached to each host in the cluster
foreach ($v in $(get-cluster -Name ClusterName | Get-VMHost)) {$v.name; Get-VMHost -name $v.Name | Get-ScsiLun | select CanonicalName,CapacityGB}
Get Canonical Name and Prefered Path of all LUNs connected to host where Path Policy is set to "Fixed" and SAN model is not "VRAID"
Get-Cluster -Name ClusterName | Get-VMHost -Name HostName | Get-ScsiLun -LunType disk | Where {$_.MultiPathPolicy -eq "Fixed" -and $_.Model -ne "VRAID"} | Get-ScsiLunPath | select ScsiCanonicalName, Name | Export-Csv -NoTypeInformation -UseCulture -Path c:\test\zone1_path.csv
Get all Equallogic datastore path policy and iop to switch path
Get-VMHost | Get-ScsiLun | Where {$_.Vendor -eq "EQLOGIC"} | select VMHost, MultipathPolicy, CommandsToSwitchPath
Get all Equallogic datastore path policy to "RoundRobin" and iop to switch path to "3"
Get-VMHost | Get-ScsiLun | Where {$_.Vendor -eq "EQLOGIC"} | Set-ScsiLun -MultipathPolicy RoundRobin -CommandsToSwitchPath 3
Display all datastores attached to ESX hosts with their Canonical Names
get-vmhost -Name HostName | Get-Datastore | Where-Object {$_.ExtensionData.Info.GetType().Name -eq "VmfsDatastoreInfo"} | ForEach-Object { if ($_) {$Datastore = $_; $Datastore.ExtensionData.Info.Vmfs.Extent | Select-Object -Property @{Name="Name";Expression={$Datastore.Name}},DiskName}}
Subscribe to:
Posts (Atom)