2

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 ?

Marios
  • 26,333
  • 8
  • 32
  • 52
J.Lin
  • 21
  • 4
  • You might want to consider storing the public address objects in a separate csv file. It depends on whether or not you are going to capture the same properties. Storing data about objects with different properties in the same file can get awfully messy. – Walter Mitty Nov 07 '20 at 10:50
  • So what's the relation between the Azure Disk and the Public IP address? – Senior Systems Engineer Nov 07 '20 at 11:57
  • I'm trying to list unattached IP (to VMs) or Disk (to VMs) in a .csv file – J.Lin Nov 07 '20 at 15:04
  • Currently, I'm just trying to put everything in a single file, need to practice my powershell a bit, but I'm struggling to find a way to list what i want .. – J.Lin Nov 07 '20 at 15:06

1 Answers1

1

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.

Jeter-work
  • 782
  • 7
  • 22