Powercli : One-liners
Over the last few months I started learning Powercli and wrote different
PowerCLI One-liners while working. I will add more in the list later on by
updating this post.
-
Get all VM names with powerstat in a cluster and export result to a csv :-
Get-Cluster mycluster| Get-VM | select Name, PowerState |Export-CSV
'C:\Users\aj\Desktop\test.csv'
-
Get a list of all VMs in a cluster and the datastore in which the VMs
resides
Get-Cluster | Get-VM | select name,
@{N="Datastore";E={Get-Datastore -VM $_}} | sort name
-
Get poweron VM names :-
Get-VM | select name,powerstate | ?{$_.powerstat -match
"PowerON"}
-
Get vmware tools status :-
Get-vm |% { get-view $_.id } | select Name, @{ Name=”Tools Status”;
Expression={$_.guest.toolsstatus}}, @{ Name=”Tools Running Status”;
E={$_.guest.toolsrunningstatus}}
-
Enable SSH on all hosts
Get-VMHost | Foreach {Start-VMHostService -HostService ($_ |
Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
-
Check on which hosts SSH is enabled
Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" }
|select VMHost, Label, Running
-
Get esx info with additional details like dc name , build
number,model,cpu,memory etc :-
get-vmhost | Select Name, @{N="Cluster";E={Get-Cluster -VMHost
$_}},@{N="Datacenter";E={Get-Datacenter -VMHost $_}},
Manufacturer,Model,Version,Build,NumCpu,@{N="MemoryTotal(GB)";
E={[math]::round($_.MemoryTotalGB)}}| Export-csv
'C:\Users\aj\Desktop\esxinfo.csv'
-
Lockdown mode enable/disbale :-
$Scope = Get-VMHost #This will change the Lockdown Mode on all hosts
managed by vCenter
foreach ($ESXhost in $Scope) {
(get-vmhost $ESXhost | get-view).ExitLockdownMode() # To DISABLE Lockdown
Mode
#(get-vmhost $ESXhost | get-view).EnterLockdownMode() # To ENABLE Lockdown
Mode
}
good one
ReplyDelete