PowerShell case sensitivity variables

Question:

I want to write a script that does a manipulation on users in my company.

Usernames can be with capital letters/small letters, and also the domain name is sometimes assigned to them with capital letters, so a username can be like:
domain\username, DOMAIN\USERNAME, DOMAIN\username or domain\USERNAME.

I ask for the username like this:

How can I make $user non case sensitive and also the company name?

The username needs to be like $company\$user without case sensitivity.

Answer:

String comparisons in PowerShell are typically case-insensitive by default.

Strings themselves are case aware, meaning they know that an A is a different glyph than an a and it will remember which was used, but the normal comparison operators (-eq, -match, -like, -lt, -in, etc.) are all case-insensitive.

You have to specify the case-sensitive versions for case-sensitive comparisons (-ceq, -cmatch, -clike, -clt, -cin, etc.). You can also specify the explicitly case-insensitive operators (-ieq, -imatch, -ilike, -ilt, -iin, etc.).

If you want to force the characters to a specific case, you can do this:

But there is no property of strings that marks them as inherently case-insensitive.

Source:

PowerShell case sensitivity variables by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply