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:
$user = Read-Host "Please insert username"
How can I make $user non case sensitive and also the company name?
The username needs to be like $company\$user without case sensitivity.
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:
#Set characters to lower case
$user = $user.ToLower();
#Set characters to upper case
$user = $user.ToUpper();
But there is no property of strings that marks them as inherently case-insensitive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With