[英]Powershell query with -like and wildcard
I currently use this script, called with -name nameofuser to get the current owner of a computerobject. 我当前使用此脚本(以-name nameofuser调用)来获取计算机对象的当前所有者。 problem is that if i write USER NAME i get results containing both USER and NAME not just "USER NAME"'s objects.
问题是,如果我写USER NAME,我将得到包含USER和NAME的结果,而不仅仅是“ USER NAME”的对象。
param(
[string]$name
)
$1 = Get-ADComputer -filter * -Properties * | Where-Object {$_.ManagedBy -like "*$name*"}
$1 = $1.name
IF ($1 -eq $Null)
{
Write-Host "Unable to find computer with manager named : " -NoNewline
Write-Host "$name" -ForegroundColor Red
}
else
{
Write-Host "Computername is : " -ForegroundColor DarkGreen -NoNewline
Write-Host "$1" -ForegroundColor Green
}
Instead of using -like try using -match. 代替使用-like尝试使用-match。 You wouldn't need a wildcard then.
那您就不需要通配符了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.