0

当我运行以下脚本时,它返回:@{Name=<Usersname>} not found

Foreach ($object in Get-childitem "\\HomeDriveServer\home$\" | select Name)
{
$userAccount = get-aduser -Filter {SamAccountName -like "*$object*"}
if($userAccount -eq $null)
    {
write-host "$object not found"
    }
else
    {
write-host "$object found"
    }
}

Get-childitem "\\HomeDriveServer\home$\" | select Name返回没有@{Name=XXX的文件夹名称列表}

为什么会出现@{Name=XXX },我该如何摆脱它?

谢谢

4

1 回答 1

0

你看到的并不完全是你得到的。您的查询返回一个集合。你应该试试 :

Foreach ($object in Get-childitem "\\HomeDriveServer\home$\" | select -ExpandProperty Name)
{
$userAccount = get-aduser -Filter {SamAccountName -like "*$object*"}
if($userAccount -eq $null)
    {
write-host "$object not found"
    }
else
    {
write-host "$object found"
    }
}
于 2013-02-01T13:50:31.827 回答