title: Azure Powershell Script
body: <p>I have written a PowerShell script to print VM names with unmanaged disks however it's giving me an error. Appreciate any help on this - </p>
  
  <pre><code>$location=Read-Host -Prompt 'Input location for VMs'
  $azuresubscription=Read-Host -Prompt 'Input Subscription Id'
  
  $rmvms=Get-AzurermVM
  # Add info about VM's from the Resource Manager to the array 
  foreach ($vm in $rmvms) 
  {     
      # Get status (does not seem to be a property of $vm, so need to call Get-AzurevmVM for each rmVM) 
      $vmstatus = Get-AzurermVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName -Status  | where Location -like $location
  
      # Add values to the array: 
      $vmarray += New-Object PSObject -Property @{` 
          # Subscription=$Subscription.SubscriptionName; ` 
          Subscription=$azuresubscription.SubscriptionName; `
          AzureMode="Resource_Manager"; ` 
          Name=$vm.Name; PowerState=(get-culture).TextInfo.ToTitleCase(($vmstatus.statuses)[1].code.split("/")[1]); ` 
          Size=$vm.HardwareProfile.VirtualMachineSize} 
  }
  
  foreach ($vm in $vmarray)
  {
      $vmdiskstatus = (Get-AzurermVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName).StorageProfile.OsDisk.ManagedDisk
      if (!$vmdiskstatus) {Write-Host $vm.Name}
  }
  </code></pre>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>($vmarray is resulting in Null array) -</p>
    
    <p>Cannot index into a null array.</p>
    
    <p>Expected Output - $vmarray should have one VM as there is a running
    instance in eastus (that's what I am using as value for $location)</p>
  </blockquote>