Azure Powershell Command return json format.

Hi All,

I need find all the internal and external loadblancers within my azure subscriptions. However when I type get-azurermloadbalancer it returns results in json format, however to I get the results in normal format?

Regards,
Kelly
Kelly GarciaSenior Systems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
I think you're misinterpreting some of what you see.  You can see all the properties returned by running
Get-AzureRmLoadBalancer | gm
The values of the properties which are collections appear as JSON, but even then, PowerShell is perfectly capable of handling JSON.  So you can run something like below and PS will parse it into properties and values just like normal.
Get-AzureRmLoadBalancer | Select -expand probes
0
Kelly GarciaSenior Systems AdministratorAuthor Commented:
i have the script below:

Connect-AzureRmAccount

$Subs = Get-AzureRmSubscription
$arr = @()
foreach($sub in $Subs){
    Set-AzureRmContext -SubscriptionObject $sub

    $lb = Get-AzureRmLoadBalancer

    $arr += $lb
}


$arr | select Name,ResourceGroupName,Location,Probes,ProvisioningState,ResourceGuid,sku,tag, tagstable,BackendAddressPools, etag, FrontendIpConfigurations,Id,LoadBalancingRules | Export-Csv -Path C:\CG_loadbalancers.csv -NoClobber -NoTypeInformation

Open in new window


however when i open the csv file, the probes field as well some others dont have the values instead it has:
System.Collections.Generic.List`1[Microsoft.Azure.Commands.Network.Models.PSProbe]

Please help!
0
Kelly GarciaSenior Systems AdministratorAuthor Commented:
for the tag it outputs:

System.Collections.Hashtable
0
footechCommented:
Export-CSV is only capable of outputting string values, so if the value of a property isn't a string, and isn't able to be simply converted to a string (something like an Int16 type can be easily converted to a string type, while a collection/array (and many other types) cannot), then you will get output like you're seeing.  The "Probes" property itself has many properties  You will need to create calculated properties such that the values are strings if you really need to export to a .CSV format.
Here's an example:
Get-AzureRmLoadBalancer |
 Select name,@{n="ProbeName";e={$_.probes.name}},
            @{n="ProbeProtocol";e={$_.probes.protocol}},
            @{n="ProbePort";e={$_.probes.port}} |
 Export-Csv -Path C:\CG_loadbalancers.csv -NoClobber -NoTypeInformation

Open in new window


If you just need to export to a file (disregarding format) for later examination, then I suggest using Export-CliXml.  That can handle all the complex data types (like properties of properties of properties) without creating calculated properties, and you can import the file and view all the properties and values later.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.