Erwin Pombett
asked on
I have a PS command that respond as expected, Same command into a function (with a variable) things wont work, what's wrong ?
helllo all of you,
I dont understand how a variable is replaced in filter used with Get-ADcomputer.
the following function is generating an error :
but the following line is giving the expected answer
what am i missing with my function ?
thank you in advance for your help.
I dont understand how a variable is replaced in filter used with Get-ADcomputer.
the following function is generating an error :
function GetComputerListForAService([string] $serviceIdentifier = "A0001", [string] $machineType )
{
$computerlist = Get-ADComputer -Filter "Name -like '*$serviceIdentifier*'" | select -expand name
return $computerlist
}
but the following line is giving the expected answer
PS > Get-ADComputer -Filter "Name -like '*A0001*'" | select -expand name
what am i missing with my function ?
thank you in advance for your help.
ASKER
hello aikimark,
thank you for your reply.
i dont get any output with curly around the filter.
i'm looking to pass the "A0001" as a parameter and have it replaced in the powershell line.
Thank you for further help
thank you for your reply.
i dont get any output with curly around the filter.
i'm looking to pass the "A0001" as a parameter and have it replaced in the powershell line.
Thank you for further help
ASKER
I also try this without success:
function GetComputerListForAService ([string] $serviceIdentifier = "A0001")
{
$computerlist = Get-ADComputer -Filter {Name -like "*$($serviceIdentifier)*"} | select -expand name
return $computerlist
}
function GetComputerListForAService
{
$computerlist = Get-ADComputer -Filter {Name -like "*$($serviceIdentifier)*"}
return $computerlist
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Odd that you're running into a problem with what you posted originally. It works for me (using PS 3.0).
You may want to read this question, as it explains the variations in behavior seen with filter syntax.
https://www.experts-exchange.com/questions/28514109/How-do-I-reference-this-object-variable.html
You may want to read this question, as it explains the variations in behavior seen with filter syntax.
https://www.experts-exchange.com/questions/28514109/How-do-I-reference-this-object-variable.html
ASKER
my question was : how can i use such selection in a function.
Open in new window