Forum Discussion
Function within a pipline - Returns wrong value
- Nov 07, 2018
Well for starters, your list of users has a strict filter that will only return the ones with "user" in their samaccountname, are you sure you have enough matches and are those users actually members of the two groups? Next, your function doesn't return any value, instead it writes output. Change it to use the return statement. Well technically both should work, but I prefer "return" :)
Lastly, when using calculated properties, you need to use the $_.Name format instead of just "name". So this:
$users | Select-Object name, mail, SamAccountName, @{n="License";e={Get-LicenseType $_.name}} | Export-Csv C:\PS-Output\$((Get-Date).ToString('yyyyddMM'))-Users.csv -Append -Encoding UTF8 –NoTypeInformation
 
Well for starters, your list of users has a strict filter that will only return the ones with "user" in their samaccountname, are you sure you have enough matches and are those users actually members of the two groups? Next, your function doesn't return any value, instead it writes output. Change it to use the return statement. Well technically both should work, but I prefer "return" :)
Lastly, when using calculated properties, you need to use the $_.Name format instead of just "name". So this:
$users | Select-Object name, mail, SamAccountName, @{n="License";e={Get-LicenseType $_.name}} | Export-Csv C:\PS-Output\$((Get-Date).ToString('yyyyddMM'))-Users.csv -Append -Encoding UTF8 –NoTypeInformation
Thank you Vasil!
It actually worked when I changed to $_.name :-)
But I like to make my small function better, so I will add "return" to my script  aswell.
Sorry to put you of by my filter, I just added "user" as an example.
I now have the list I need! Thanks again! :)
// Julian