【发布时间】:2017-02-17 13:17:28
【问题描述】:
我有以下 PowerShell 脚本
$server = Get-ADComputer -filter {name -like $computerhost}
write-host $server.name
它为我提供了名称中包含 $computerhost 的 ADComputer。
例子:
$computerhost = linuxserver
匹配的计算机名输出:“linuxserver01”
但如果计算机名称适合 $computerhost,我实际上想要 ADComputer。因此,如果 $computerhost 是“asdf”,我想获得名称为“a”或“as”或“asd”或“asdf”的计算机,而不是“asda”
例子:
$computerhost = linuxserver (new)
匹配的计算机名输出:“linuxserver”
我不知道如何以这种方式使用通配符。
【问题讨论】:
-
但我实际上想要 ADComputer,它适合 $computerhost。 我实际上不知道你的意思是什么?您只想从
$computerhost中搜索部分名称?那你如何决定要删除什么? -
如果 AD 中的计算机名称适合 $computerhost。因此,如果 $computerhost 是“asdf”,我想获得名称为“a”或“as”或“asd”或“asdf”的计算机,而不是“asda”。
标签: powershell active-directory wildcard