2

I am trying to get the value and format in a certain way. I tried a few methods but it didn't work. I am new to Powershell and still learning.

Add-Content -Path data.csv -Value ‘"Type","Res","Size”'
$aList= @()

 $Accountinfo = Get-AzStorageAccount -ResourceGroupName $resName
        IF ($($Accountinfo).count -gt 0) {
            foreach ($accountiinform in $Accountinfo) {
                $Names = "Storage Account"
                $props = [ordered]@{
                    "Res" = $Names
                    "Name"     = $accountiinform.StorageAccountName
                }
                $aList += New-Object pscustomobject -Property $props
            }
        }
    # There are more if statement-checking more resources and adding the $props object to $alist

$aList | foreach { Add-Content -Path data.csv -Value $_ }

what data.csv has:

"Type","Res","Size"
@{Res=Storage Account; Name=dataStorage;}
@{Res=VM; Name=dataVM; Size=250 GB;}
@{Res=VM; Name=dataVM2; Size=500 GB;}

What I want:

"Type","Res","Size"
Storage Account, Name=dataStorage,
VM,dataVM, 250 GB
VM, dataVM2,500 GB

1 Answer 1

3

Please change the last line to:

Replace
$aList | foreach { Add-Content -Path data.csv -Value $_ }

With this:
$aList | Export-Csv -Path C:\Temp\data.csv -NoTypeInformation
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.