Azure Azure Power Shell command RRS feed

  • Question

  • Hi All,

    I am looking for azure arm power shell script which can give me output for my all azure machines Name,Size,Power on/Power off,Public IP,Private IP,location,subnet name,vnetname,storageaccountname,data disk and OS disk name in CSV or excel format.

    I have the below powershell script but its not helping me out. Please help.

    # Get your VM object
    $vm = Get-AzureRmVM -Name "Your_VM" -ResourceGroupName "Your_RG" 
    #VM Size
    $vmSize = $vm.HardwareProfile.VmSize
    Write-Host $vmSize
    # VM Name
    $vmName = $vm.Name
    Write-Host $vmName 
    # VM State
    $state = $vm.ProvisioningState
    Write-Host $state 
    # VM Location
    $location = $vm.Location
    Write-Host $location 
    $NIC = Get-AzureRmNetworkInterface  | where { $_.Id -eq $vm.NetworkProfile.NetworkInterfaces[0].Id }
    if($NIC -ne $null){
        # Private IP address of VM
        $privateIPAddress = $NIC.IpConfigurations[0].PrivateIpAddress  
        Write-Host $privateIPAddress 
         # Public IP Address of VM
         $publicIpAddress = (Get-AzureRmPublicIpAddress | where {$_.Id -eq $NIC.IpConfigurations[0].PublicIpAddress.Id}).IpAddress
        Write-Host $publicIpAddress 
        #Subnet Name
        $subnetConfig = Get-AzureRmResource -ResourceId  $NIC.IpConfigurations[0].Subnet.Id
        $subnetName = $subnetConfig.Name
        Write-Host $subnetName
        $vm = Get-AzureRmVM -Name "VM1" -ResourceGroupName "BGLBRG" -Status
        if($vm.VMAgent -ne $null) {
                # VM Agent Status
                $vmStatus = $vm.VMAgent.Statuses[($vm.VMAgent.Statuses.Count) - 1].Code
                Write-Host $vmStatus 

    Nirmal Singh IT Administrator

    Thursday, January 12, 2017 2:40 PM