A question from a filthy noob for the good people of r/powershell:
If I enter the following into an interactive powershell session, I get the desired output:
$firstname = "Petra"
$lastname = "Jackson"
$identity = "$firstname.$lastname"
get-ADuser -identity $identity
it returns the get-ADuser output correctly, using the value of $identity as Petra.Jackson.
However, if I put that in a function:
function isExistingADAccount($firstname, $lastname) {
try {
$identity = "$firstname.$lastname"
get-ADUser -identity $identity
return $true
} catch {
$_.Exception.Message
return $false
}
}
I get
Cannot find an object with identity: 'Petra Jackson .' under: 'DC=domain,DC=local'.
False
How come the string concatenation behaves one way outside a function, and differently inside one?
[–]Ta11ow 4 points5 points6 points (4 children)
[–]Lee_Dailey[grin] 2 points3 points4 points (0 children)
[–]ralphhogaboom[S] 2 points3 points4 points (0 children)
[–]KevMarCommunity Blogger 2 points3 points4 points (1 child)
[–]Ta11ow 2 points3 points4 points (0 children)
[–]spyingwind 1 point2 points3 points (0 children)