title: Powerstate of Azure VM through powershell
body: <p>Fragment of my script looks like this:</p>
  
  <pre><code># Collection of data
  $VMs = Get-AzureRmVM
  $vmOutput = $VMs | ForEach-Object { 
      [PSCustomObject]@{
          "VM Name" = $_.Name
          "VM Type" = $_.StorageProfile.osDisk.osType
          "VM Profile" = $_.HardwareProfile.VmSize
          "Environment" = $_.Tags.Environment
          "Application" = $_.Tags.Application
          "Decommission Date" = $_.Tags.Decomission
          "OS Disk Size" = $_.StorageProfile.OsDisk.DiskSizeGB
          "Data Disks Total Size" = ($_.StorageProfile.DataDisks.DiskSizeGB | Measure -Sum).Sum
          "Data Disks Amount" = ($_.StorageProfile.DataDisks.DiskSizeGB | Measure ).Count
          "Powerstate" = $_.Statuses[1].DisplayStatus
      }
  }
  
  $vmOutput | sort "Environment", "VM Type", "VM Profile", "Application" | export-csv VMReport.csv -delimiter ";" -force -notypeinformation 
  </code></pre>
  
  <p>I want to add a power state column to the report, but it's not included in <em>Get-AzureRMVM</em> properties. I must add <em>-status</em> at the end of command to show me this data, but as I've noticed, it only works when specific resource group name and vm name is included. </p>
  
  <p>How can I change the script to include power state as the last column in report without throwing this script away and writing a new one from scratch?</p>