【发布时间】:2020-02-12 22:03:16
【问题描述】:
当我在数组的数组中输出元素时(例如:$data_array[0][0],我只得到一个字符。这是为什么呢?我期待 [0][ 的字符串为 LAP-150 0] 这个数组的位置。
import-module activedirectory
$domain_laptops = get-adcomputer -filter 'Name -like "LAP-150"' -properties operatingsystem, description | select name, description, operatingsystem
$data_array = @()
foreach ($laptop in $domain_laptops){
$bde = manage-bde -computername $laptop.name -status
$encryptionstatus=(manage-bde -status -computername $laptop.name | where {$_ -match 'Conversion Status'})
if ($encryptionstatus){
$encryptionStatus=$encryptionstatus.split(":")[1].trim()
}
else{
$EncryptionStatus="Not Found..."
}
$data_array += ,($laptop.name,$laptop.description,$laptop.operatingsystem,$encryptionstatus)
}
write-output $data_array[0][0]
上述脚本的输出只是字符“L”,它是 $laptop.name 变量中的第一个字符。我哪里错了?我认为这与我附加到数组的方式有关,但我尝试了不同的括号、逗号、无括号等组合,但无济于事。
【问题讨论】:
标签: arrays powershell loops