Get-ADComputer没有找到主机名,但我可以手动找到它



所以我有一个永远工作的脚本,我从来没有看过它。然而,它突然停止了工作。当我尝试使用Get-ADComputer命令在AD中搜索主机名时,它返回以下错误消息:

Get-ADComputer: Cannot find an object with identity: 'hostname' under: 'DC=domain,DC=name,DC=edu'

即使我尝试一个基本的Get-ADComputer hostname,它返回相同的错误信息。但是,如果我自己打开AD并搜索主机名,我发现它很好。AD和Powershell之间似乎有某种脱节。

还有人遇到这个基本的PS cmlet不能正常工作吗?

明白了。我把"$ComputerName"写成了$ComputerName,没有引号。不知道为什么我需要搜索"喜欢"的东西。计算机名,而不是名称本身,但它是有效的。最后的脚本看起来像这样:

Param(
[Parameter(Mandatory=$True)]
[string]$ComputerName
)
echo ""
echo ""
$Properties =
@(
'CanonicalName',
'Enabled',
'Created',
'LastLogonDate',
'IPv4Address',
'OperatingSystem',
'OperatingSystemServicePack',
'OperatingSystemVersion'
)
Get-ADComputer -Filter 'Name -like $ComputerName' -Properties $Properties | select $Properties```

相关内容

最新更新