0

The script does is to Go to each of the Azure Subscription and then list the VM properties and then create the PSObjects to capture the output in a meaningful and useful format.

Get-AzSubscription | ForEach-Object {
    $subscriptionId = $_.Id
    $subscriptionName = $_.Name
     
    Set-AzContext -SubscriptionId $subscriptionId

    $VM = Get-AzVM

    # Get NIC id
    $NICId = $VM.NetworkProfile.NetworkInterfaces[0].id
    
    # Get NIC
    $NIC = Get-AzNetworkInterface -ResourceId $NICId
    
    # Get public ip id
    $PIPId = $NIC.IpConfigurations.PublicIpAddress.id
    
    # Get public ip
    $PIP = Get-AzResource -ResourceId $PIPId
    
    # Output
    [pscustomobject]@{
        Subscription             = $subscriptionName
        VMName                   = $VM.Name
        VMRG                     = $VM.ResourceGroupName
        VMLocation               = $VM.Location
        IpAddress                = $PIP.Properties.ipAddress
        PublicIPAllocationMethod = $PIP.Properties.publicIPAllocationMethod
        FQDN                     = $pip.Properties.dnsSettings.fqdn
    }
} | Out-GridView

However, the result is mixed up and not in the correct format like the below:

Out-GridView

enter image description here

Format-Table -Autosize

Subscription             : Corp-Azure-Dev-subs
VMName                   : {prod1-build, corpbuild-image, corpplus-build-server, u2api...}
VMRG                     : {corp-prod1-BUILD, corp-PLUS-BUILD-SETUP, corp-PLUS-BUILD-SETUP, ERP-Acorp-DEV...}
VMLocation               : {eastus, east, centralus, westus...}
IpAddress                : 52.44.66.198
PublicIPAllocationMethod : Static
FQDN                     : 
1
  • 2
    Why does Format-Table -AutoSize look like Format-List in the question? Commented Nov 23, 2020 at 4:22

1 Answer 1

3

I think you're outputting multiple object types. From the looks of it the line:

Set-AzContext -SubscriptionId $subscriptionId

Might be causing the issue. Remember anything you output is fed down the pipe. So, the likely problem is Out-Griview doesn't know what to do with a multi-typed array. Try sending that like to Out-Null to see if it rights the Out-GridView result.

Sign up to request clarification or add additional context in comments.

1 Comment

You are correct @steven, that does make sense., tired eyes can cause the issue. thank you sir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.