I currently use this script, called with -name nameofuser to get the current owner of a computerobject. problem is that if i write USER NAME i get results containing both USER and NAME not just "USER NAME"'s objects.
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. You wouldn't need a wildcard then.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.