测试 1 按预期工作。为什么测试 2 的工作方式不同?
$user="bsimms"
Write-Host "test 1"
$test1out=Get-ADUser $user -Properties * | Select-Object -Property Name, samAccountName, EmployeeID
Write-Host "test1: $test1out"
$myitems="Name, samAccountName, EmployeeID"
Write-Host "test 2"
$test2out=Get-ADUser $user -Properties * | Select-Object -Property $myitems
Write-Host "test2: $test2out"
Output C:\>powershell .\file.ps1
test 1
test1: @{Name=Bob Simms; samAccountName=bsimms; EmployeeID=0123450}
test 2
test2: @{Name, samAccountName, EmployeeID=Microsoft.ActiveDirectory.Management.ADPropertyValueCollection}