需要帮助将每个循环的输出存储到变量中并导出到csv文件。
我没有尝试过。我没有想法
下面是我的脚本
$disks = Get-AzDisk
Foreach($disk in $disks)
{
if($disk.ManagedBy -eq $VM.Id)
{
$diskname = $disk.Name
$encryptionsettings = $disk.EncryptionSettingsCollection
if($encryptionsettings -eq $null)
{
$encryption = "Not encrypted"
}
else
{
$encryption = "Encrypted"
}
}
$VM | Select-Object @{Name="Disk Name";Expression={$diskname}},
@{Name="Encryption Status";Expression={$encryptionstatus}} | Export-Csv -Path $VMDetails -Delimiter "," -NoTypeInformation -Append
}
我需要输出为
Disk Name Encryption status
test , test1 , test2 , test3 Encrypted , Not encrypted,Encrypted ,Encrypted
但是我得到的输出如下。
Disk Name Encryption Status
test Not encrypted
test_DataDisk_0 Encrypted
test_DataDisk_1 Encrypted
test_OsDisk_1_aa301d403d1e46f6b2af9a49a0f46052 Encrypted