James
 Basic Member Posts:374

 |
| 22 Jan 2010 04:19 AM |
|
Hello,
I have the following code:
Get-QADObject -Type User Where-Object {$_.UserPrincipalName -cne $_.UserPrincipalName.Lower()} Select-Object FirstName,LastName,SamAccountName,UserPrincipalName,ParentContainer | Export-Csv "c:\NonLowerCasePrincipalNames.csv"
Basically I am after trying to get the users that have a UPN with anything uppercase in it to be exported out. Then I am going to convert them to all lower in excel and reimport them back in so they have there proper upn's with a script I have done today. Its not working though it comes up with an error saying that it cant find a property $_.UserPrincipalName -cne $_.UserPrincipalName.Lower()
Can anyone assist me with this?
Many Thanks
James
|
|
|
|
|
Vishal Ramnani
 New Member Posts:68

 |
| 22 Jan 2010 05:13 AM |
|
First of all -cne is not correct operation. i think it should be -ne (Not Equal) however it will return the result as -ne operation will not match with lower or upper case. instead of exporting you directly change them to lower as below. Get-QADUser -SizeLimit 0 | Set-QADUser -UserPrincipalname $_.UserPrincipalName.Lower() it will take all Users in AD and change their UPN to lower case and set it back to AD. and yes, please test it with one/few IDs first by replacing -SizeLimit 0 with -id or pipe the IDs from some output. Thanks. ---------------- Thanks Shay, i correct myself. Yes is a valid operator and is to match exact case sensitive string.
|
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|
James
 Basic Member Posts:374

 |
| 22 Jan 2010 07:40 AM |
|
Hello, I have tried it with the following: Get-QADUser -Identity 'user.test' | Set-QADUser -UserPrincipalname $_.UserPrincipalName.Lower() And I get the error of: You cannot call a method on a null-valued expression. At C:\lowercaseupn.ps1:11 char:96 + Get-QADUser -Identity 'user.test' | Set-QADUser -UserPrincipalname $_.UserP rincipalName.Lower( <<<< ) Many Thanks James |
|
|
|
|
James
 Basic Member Posts:374

 |
| 23 Jan 2010 07:25 AM |
|
Hello,
I can reimport the correct principal names and such I just need to export them out first correct them and then I will be able to reimport them and it will be done.
I have the following:
Get-QADUser -SizeLimit 0 |Where-Object {$_.UserPrincipalName -ne $_.UserPrincipalName.Lower() } Select-Object Title,FirstName,LastName,SamAccountName,ParentContainer | Export-Csv "c:\NonLowerCasePrincipalNames.csv"
When I run it I get the following error:
At C:\lowercaseupn.ps1:13 char:92 + Get-QADUser -SizeLimit 0 |Where-Object {$_.UserPrincipalName -ne $_.UserPrinc ipalName.Lower( <<<< ) } Method invocation failed because [System.String] doesn't contain a method named 'Lower'.
Does anyone know whats wrong?
Many Thanks
James
EDIT: code as I pasted in the wrong one. |
|
|
|
|
James
 Basic Member Posts:374

 |
| 26 Jan 2010 07:17 AM |
|
Hello, My code is now:
Get-QADUser -Identity 'julian.test' -SizeLimit 0 |Where-Object {$_.UserPrincipalName -ne $_.UserPrincipalName.ToLower()} |
Select-Object Title,FirstName,LastName,SamAccountName,UserprincipalName,ParentContainer |
Export-Csv "c:\NonLowerCasePrincipalNames.csv"
Which runs fine however it does not export anythig to the CSV however I know there are things which should be exported. Does anyone have any suggestions? Many Thanks James |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 26 Jan 2010 01:19 PM |
|
Comparison operators in PowerShell are NOT case-sensitive, change -ne to -cne: $_.UserPrincipalName -cne $_.UserPrincipalName.ToLower() for more information see the about_Comparison_Operators help file. |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
James
 Basic Member Posts:374

 |
| 27 Jan 2010 02:41 AM |
|
Hello, Thanks for that it worked perfectly! Just one little letter made all the diffrence. Many Thanks for your help James |
|
|
|
|