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}}
Showing posts with label datastore. Show all posts
Showing posts with label datastore. Show all posts
Thursday, 6 August 2015
Tuesday, 14 July 2015
PowerCLI - How to get cluster resource information
Get cluster available resources and usage
Get-Cluster -Name ClusterName | get-vmhost | select Name, NumCpu, CpuUsageMhz, CPUTotalMhz, MemoryUsageGB, MemoryTotalGB | Export-Csv -NoTypeInformation -UseCulture -Path c:\test\vent1.csv
Get all datastores per cluster
foreach ($cluster in Get-Cluster){Add-content fi $cluster.Name; Get-cluster -name $cluster.Name | Get-Datastore | select Name, FreeSpaceGB, CapacityGB}
Get all datastores per cluster and export to txt file
foreach ($cluster in Get-Cluster){Add-content "C:\test\test.txt" "$cluster"; Add-Content "C:\test\test.txt" "Name, FreeSpaceGB, CapacityGB"; $d=Get-cluster -name $cluster.Name | Get-Datastore | select Name, FreeSpaceGB, CapacityGB; $d | % {add-content "c:\test\test.txt" "$($_.Name), $($_.FreeSpaceGB), $($_.CapacityGB)"}}
Get count of all hosts cpu cores
Get-Cluster -Name SharedEnterprisePlus01 | Get-VMHost | Measure-Object -Property NumCpu -Sum | select -ExpandProperty Sum
Get list of all NOT empty resource pools in the cluster based on pool's VM's cpu count
$ResourcePools = Get-Cluster -Name ClusterName | Get-ResourcePool
foreach ($Pool in $ResourcePools){$a = Get-ResourcePool -Name $Pool.Name | Get-VM | Measure-Object -Property NumCpu -Sum | select -ExpandProperty Sum; if($a -gt 0) {$Pool.Name}}
Get list of all VMs which have "prod" in their name and summary information about disk size
$a = get-vm | where{$_.Name -like "*prod*"}; foreach ($v in $a) {Write-Host $v.Name; Get-HardDisk -vm $v.name | Measure-Object -Property CapacityGB -Sum | select -ExpandProperty Sum}
Get list of all VMs which have "prod" in their name and summary information about disk size and write to txt file. I've used Write-Host commands to display output on the screen too.
$a = get-vm; foreach ($v in $a) {$s = Get-HardDisk -vm $v.name | Measure-Object -Property CapacityGB -Sum | select -ExpandProperty Sum; $s | %{Add-Content "d:\iso\vm.txt" "$($v.Name), $($_)"}; Write-Host $v.Name; Write-Host $s}
Get cluster available resources and usage
Get-Cluster -Name ClusterName | get-vmhost | select Name, NumCpu, CpuUsageMhz, CPUTotalMhz, MemoryUsageGB, MemoryTotalGB | Export-Csv -NoTypeInformation -UseCulture -Path c:\test\vent1.csv
Get all datastores per cluster
foreach ($cluster in Get-Cluster){Add-content fi $cluster.Name; Get-cluster -name $cluster.Name | Get-Datastore | select Name, FreeSpaceGB, CapacityGB}
Get all datastores per cluster and export to txt file
foreach ($cluster in Get-Cluster){Add-content "C:\test\test.txt" "$cluster"; Add-Content "C:\test\test.txt" "Name, FreeSpaceGB, CapacityGB"; $d=Get-cluster -name $cluster.Name | Get-Datastore | select Name, FreeSpaceGB, CapacityGB; $d | % {add-content "c:\test\test.txt" "$($_.Name), $($_.FreeSpaceGB), $($_.CapacityGB)"}}
Get count of all hosts cpu cores
Get-Cluster -Name SharedEnterprisePlus01 | Get-VMHost | Measure-Object -Property NumCpu -Sum | select -ExpandProperty Sum
Get list of all NOT empty resource pools in the cluster based on pool's VM's cpu count
$ResourcePools = Get-Cluster -Name ClusterName | Get-ResourcePool
foreach ($Pool in $ResourcePools){$a = Get-ResourcePool -Name $Pool.Name | Get-VM | Measure-Object -Property NumCpu -Sum | select -ExpandProperty Sum; if($a -gt 0) {$Pool.Name}}
Get list of all VMs which have "prod" in their name and summary information about disk size
$a = get-vm | where{$_.Name -like "*prod*"}; foreach ($v in $a) {Write-Host $v.Name; Get-HardDisk -vm $v.name | Measure-Object -Property CapacityGB -Sum | select -ExpandProperty Sum}
Get list of all VMs which have "prod" in their name and summary information about disk size and write to txt file. I've used Write-Host commands to display output on the screen too.
$a = get-vm; foreach ($v in $a) {$s = Get-HardDisk -vm $v.name | Measure-Object -Property CapacityGB -Sum | select -ExpandProperty Sum; $s | %{Add-Content "d:\iso\vm.txt" "$($v.Name), $($_)"}; Write-Host $v.Name; Write-Host $s}
Subscribe to:
Posts (Atom)