Export two or three azure cmdlets into the same .csv in powershell

Viewed 66

First thank for those who stop here and try to help !

It's my first time touching powershell.

I search a way to list and export unattached or orphaned resources in Azure (IPs, RGs, Disks ...)

Get-AzDisk | Select-Object -Property Name,AttachedTo,Location | Export-Csv -path C:\Users\David\test.csv ";"  -NoTypeInformation 

With this I only have Azdisk on a single .csv file but how can I add per example "Get-AzPublicIpAddress" into the same .csv ?

1 Answers

You want to use a script to do this, not a one-liner.

First, create a function to build a custom object with as many properties as you need, using as many commandlets as you wish. Get this to work for one object.

Learn about PSCustomObject.

Learn about functions.

Then build a loop that runs the function against all of the objects creating an array holding items which are instances of your custom object.

At the end of the loop, output to CSV.

Objects, especially custom objects, are one of the things that sets Powershell apart.

Related