Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert output of a command to lowercase in powershell

I’m running a command in PowerShell to get the list of emails in a distribution group but I need to normalize the list to do some comparisons later and I need them all in lowercase. I’ve tried multiple instances of .tolower() but nothing seems to work. How can I achieve this?

Get-AzureADGroup -ObjectId [REDACTED] | Get-AzureADGroupMember -All $True |Select-Object UserPrincipalName | Sort-Object UserPrincipalName

This gives me the output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UserPrincipalName
-----------------
First.Name@redacted.com
Jane.Doe@redacted.com
johnsmith@redacted.com
That.Person@redacted.com

I want them all in lowercase and, since we’re already here, without the header "UserPrincipalName —————–" as well. Thanks in advance.

Tried adding "tolower.()" on multiple different positions in the string. None worked. I’m getting an error that tolower is not recognized, but couldn’t find how to install it

tolower. : The term 'tolower.' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ tolower.(Get-AzureADGroup -ObjectId [REDACTED] ...
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (tolower.:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

>Solution :

You’re using Select-Object in this case to create new objects having a property name UserPrincipalName. If you want to output strings instead, you can use ForEach-Object to expand on each .UserPrincipalName value:

Get-AzureADGroup -ObjectId [REDACTED] |
    Get-AzureADGroupMember -All $True |
    ForEach-Object { $_.UserPrincipalName.ToLower() } |
    Sort-Object
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading