Difference between revisions of "Using PowerCLI in Powershell"

From Tech-Wiki
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
  PS C:\> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore  
 
  PS C:\> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore  
 
  PS C:\> Connect-VIServer 10.1.1.10
 
  PS C:\> Connect-VIServer 10.1.1.10
  PS C:\> Get-VM | Select Name,PowerState,MemoryGB,NumCpu,UsedSpaceGB   
+
  PS C:\> Get-VM | Select Name,PowerState,MemoryGB,NumCpu,UsedSpaceGB  
  PS C:\> Get-VM | Sort | Select Name, @{N="IP Address";E={$_.guest.IPAddress[0]}} | export-csv report.csv  
+
  PS C:\> Get-VM -Location 'NYC' | Select Name
  PS C:\> Get-Cluster "Test-*" | Get-VM | Get-View -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName") |
+
  PS C:\> Get-VM | Where-Object { $_.Guest.OSFullName -like '*Windows*' }  |  Select Name
 +
PS C:\> Get-VM -Location 'ADMS' | Where-Object {$_.ExtensionData.Config.GuestFullname -match "Windows" -and $_.Name -match "cstest" -and $_.PoweredState -match "PoweredOn" } | Select Name
 +
PS C:\> Get-VM | Select Name, @{N="IP Address";E={$_.guest.IPAddress[0]}} | export-csv report.csv  
 +
  PS C:\> Get-Cluster "Test-*" | Get-VM | Sort | Get-View -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName") |
 
     Select -Property Name, @{N="Running OS";E={$_.Guest.GuestFullName}} | Format-Table -AutoSize
 
     Select -Property Name, @{N="Running OS";E={$_.Guest.GuestFullName}} | Format-Table -AutoSize
  
Among commands above, hints how to deal with large columns, sorting or exporting to .csv
+
Among commands above, there are hints how to deal with large columns, sorting or exporting to .csv

Latest revision as of 14:44, 16 April 2024


How to use PowerCLI to output VM information for ESXi.

PS C:\> Install-Module -Name VMware.PowerCLI 
PS C:\> Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false 
PS C:\> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore 
PS C:\> Connect-VIServer 10.1.1.10
PS C:\> Get-VM | Select Name,PowerState,MemoryGB,NumCpu,UsedSpaceGB 
PS C:\> Get-VM -Location 'NYC' | Select Name
PS C:\> Get-VM | Where-Object { $_.Guest.OSFullName -like '*Windows*' }  |  Select Name
PS C:\> Get-VM -Location 'ADMS' | Where-Object {$_.ExtensionData.Config.GuestFullname -match "Windows" -and $_.Name -match "cstest" -and $_.PoweredState -match "PoweredOn" } | Select Name
PS C:\> Get-VM | Select Name, @{N="IP Address";E={$_.guest.IPAddress[0]}} | export-csv report.csv 
PS C:\> Get-Cluster "Test-*" | Get-VM | Sort | Get-View -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName") |
   Select -Property Name, @{N="Running OS";E={$_.Guest.GuestFullName}} | Format-Table -AutoSize

Among commands above, there are hints how to deal with large columns, sorting or exporting to .csv