I've tried to create a powershell script which allows me to find the correct computer by it's service tag in AD. So far I could do it by writing the service tag in the script, but when I wanted to pass it with variable, it doesn't let me do it, and shows this error:
Get-ADComputer : A positional parameter cannot be found that accepts argument 'GCX0YY1"'. At line:2 char:1 + Get-ADComputer -Filter 'Name -like "*'$name'"'
$name = Read-Host 'Write the computers service tag'
Get-ADComputer -Filter 'Name -like "*'$name'"'
The $name
variable doesn't get resolved if you use single quotes on your string. You could use a string format (alias -f
) to get your variable in place:
$name = Read-Host 'Write the computers service tag'
Get-ADComputer -Filter ('Name -like "{0}"' -f $name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With