Forum Discussion

Julian Revheim Askeland's avatar
Julian Revheim Askeland
Copper Contributor
Nov 06, 2018
Solved

Function within a pipline - Returns wrong value

Hi Everyone ,   I'm trying to create a list of user, and witch Office 365 license they have based on membership in an AD group. I have created a simple function for that myself, and it appears to b...
  • VasilMichev's avatar
    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

     

Resources