#powershell #csv #azure-powershell
#powershell #csv #azure-powershell
Вопрос:
Я пытаюсь получить значение и формат определенным образом. Я попробовал несколько методов, но это не сработало. Я новичок в Powershell и все еще учусь.
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 $_ }
какие данные.csv имеет:
"Type","Res","Size"
@{Res=Storage Account; Name=dataStorage;}
@{Res=VM; Name=dataVM; Size=250 GB;}
@{Res=VM; Name=dataVM2; Size=500 GB;}
Что я хочу:
"Type","Res","Size"
Storage Account, Name=dataStorage,
VM,dataVM, 250 GB
VM, dataVM2,500 GB
Ответ №1:
Пожалуйста, измените последнюю строку на:
Replace
$aList | foreach { Add-Content -Path data.csv -Value $_ }
With this:
$aList | Export-Csv -Path C:Tempdata.csv -NoTypeInformation