PowerCLI Code

Some basic PowerCLI commands


#Here are some basic commands that you can keep adding additional code
#and get more precise on what you want to see.

#Connect to a vCenter

Connect-VIServer vcsa.domain.org

#Disconnect from vCenter and not be prompted

Disconnect-VIServer vcsa.domain.org -confirm:$false

#Get VM Listing

#Shows all VMs
Get-VM

#Shows all VMs sorted by Name
Get-VM | Sort-Object Name

#Shows all VMs sorted by Name that are Powered On
Get-VM | Where-Object {$_.Powerstate -eq 'PoweredOn'} | Sort-Object Name

#Shows all VMs sorted by Name, that are Powered On and only shows
#Name,MemoryGB,NumCpu
Get-VM | Where-Object {$_.Powerstate -eq 'PoweredOn'} | Sort-Object Name | Select-Object Name,MemoryGB,NumCpu