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 ?

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. Commented Nov 7, 2020 at 10:50
  • So what's the relation between the Azure Disk and the Public IP address? Commented Nov 7, 2020 at 11:57
  • I'm trying to list unattached IP (to VMs) or Disk (to VMs) in a .csv file Commented Nov 7, 2020 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 .. Commented Nov 7, 2020 at 15:06

1 Answer 1

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.

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

Comments

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.