Quantcast
Viewing all articles
Browse latest Browse all 182084

Re: Getting HA-status from PowerCLI

If you're not yet using PowerShell v3, you can do it this way to get the order in the CSV file.

 

&{Get-View-ViewTypeVirtualMachine|%{
 
New-ObjectPSObject-Property@{
   
Name=$_.Name
   
Host=Get-View$_.Summary.Runtime.Host|Select-ExpandPropertyName
   
Cluster=Get-Cluster-VM$_.Name|Select-ExpandPropertyName
   
Datastores= [system.String]::Join(",",($_.Storage.PerDatastoreUsage|%{Get-View$_.Datastore} |%{$_.Name}))
   
ProvisionedGB= [math]::Round( ($_.Storage.PerDatastoreUsage|Measure-Object-PropertyCommitted-Sum|Select-ExpandPropertySum)/1GB,1)
   
NumCPU=$_.Config.Hardware.NumCPU
   
NumvCPU=&{if($_.Config.Hardware.NumCoresPerSocket-gt0){$_.Config.Hardware.NumCPU/$_.Config.Hardware.NumCoresPerSocket}}
   
DASStatus=&{if($_.Runtime.dasvmprotection.dasProtected){$_.Runtime.dasvmprotection.dasProtected}else{$false}}
  }
}}
|SelectName,Host,Cluster,Datastores,ProvisionedGB,NumCPU,NumvCPU,DASStatus|
Export-Csv"C:\Powershell\VM-report.csv"-NoTypeInformation-UseCulture

If you are using PowerShell v3, you can do

 

&{Get-View-ViewTypeVirtualMachine|%{
 
$object= [ordered]@{
   
Name=$_.Name
   
Host=Get-View$_.Summary.Runtime.Host|Select-ExpandPropertyName
   
Cluster=Get-Cluster-VM$_.Name|Select-ExpandPropertyName
   
Datastores= [system.String]::Join(",",($_.Storage.PerDatastoreUsage|%{Get-View$_.Datastore} |%{$_.Name}))
   
ProvisionedGB= [math]::Round( ($_.Storage.PerDatastoreUsage|Measure-Object-PropertyCommitted-Sum|Select-ExpandPropertySum)/1GB,1)
   
NumCPU=$_.Config.Hardware.NumCPU
   
NumvCPU=&{if($_.Config.Hardware.NumCoresPerSocket-gt0){$_.Config.Hardware.NumCPU/$_.Config.Hardware.NumCoresPerSocket}}
   
DASStatus=&{if($_.Runtime.dasvmprotection.dasProtected){$_.Runtime.dasvmprotection.dasProtected}else{$false}}
  }
 
New-ObjectPSObject-Property$object
}}
|Export-Csv"C:\VM-report.csv"-NoTypeInformation-UseCulture

Viewing all articles
Browse latest Browse all 182084

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>