Hi,
Some of our computer names are derived from the computer asset number which has worked well for us for a long time. The issue we get is when a user provides us with just the asset number. Performing any task on that computer first requires us to get the computer name.
A simple one liner will get the computer from AD as below:
Get-ADComputer -Filter 'name -like "*12345"'
In order to pass a value to it, a variable was created and used
$WCComputer = "*$Computer" Get-ADComputer -Filter 'name -like $WCComputer'
This was part of a bigger script and was used to pass the ADComputer name through the pipeline This all works fine until an AD object is not returned, then null is passed.
For some reason when you use the filter parameter you can’t trap the fact that an object isn’t found. If I use either line below I get an error I can manage.
Get-ADComputer -Identity '*12345' or Get-ADComputer -Identity $WCComputer
It appears that using the Identity parameter doesn’t error. Can anyone help me get around this please ?
Any help would be much appreciated.
Thanks