![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Listing out all usernames with space Hi! It seems that we have a bunch of users whose sAMAccountName and userPrincipalName fields contain space characters. This is a mistake that was caused by some serious cut 'n paste work done by our user account management. So I need to list all the users whose sAMAccountName contains the space character and then fix them. For example the value could be: "abc1234 " <- so this is the case mostly, the space is located in the end of the sAMAccountName or "abc 1234" <- it could be in the middle or " abc1234" <- it could be in the start Does query: GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { $_.LogonName -like "* *" } .... return all the cases listed above? If I now have them in the pipeline how can I remove all the spaces from the sAMAccount -field (so no parsing on Name -field and so on!)? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Listing out all usernames with space Kari wrote: > Hi! > > It seems that we have a bunch of users whose sAMAccountName and > userPrincipalName fields contain space characters. This is a mistake that was > caused by some serious cut 'n paste work done by our user account management. > > So I need to list all the users whose sAMAccountName contains the space > character and then fix them. For example the value could be: > "abc1234 " <- so this is the case mostly, the space is located in the end of > the sAMAccountName > or > "abc 1234" <- it could be in the middle > or > " abc1234" <- it could be in the start > > Does query: > GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { > $_.LogonName -like "* *" } > ... return all the cases listed above? > > If I now have them in the pipeline how can I remove all the spaces from the > sAMAccount -field (so no parsing on Name -field and so on!)? Although I was surprised it was that easy, it does appear that "* *" will work... I thought you'd need a more complex regular expression. PS C:\> "test" -like "*" True PS C:\> "test" -like "* " False PS C:\> "test ing" -like "* " False PS C:\> "test ing" -like "* *" True PS C:\> " testing" -like "* *" True PS C:\> "testing " -like "* *" True PS C:\> |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Listing out all usernames with space "Kari" wrote: > Hi! > > It seems that we have a bunch of users whose sAMAccountName and > userPrincipalName fields contain space characters. This is a mistake that was > caused by some serious cut 'n paste work done by our user account management. > > So I need to list all the users whose sAMAccountName contains the space > character and then fix them. For example the value could be: > "abc1234 " <- so this is the case mostly, the space is located in the end of > the sAMAccountName > or > "abc 1234" <- it could be in the middle > or > " abc1234" <- it could be in the start > > Does query: > GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { > $_.LogonName -like "* *" } > ... return all the cases listed above? Yep, I think this should work. Another way would be: PS> ' brat wurst banane '.ToCharArray() -contains ' ' True > If I now have them in the pipeline how can I remove all the spaces from the > sAMAccount -field (so no parsing on Name -field and so on!)? PS> $newname = ' brat wurst banane ' -replace ' ','' PS> $newname bratwurstbanane -- greetings dreeschkind |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Listing out all usernames with space "dreeschkind" <dreeschkind@discussions.microsoft.com> wrote in message news:7D957437-8F74-479F-9297-B5DB218FFADF@microsoft.com... > "Kari" wrote: > >> Hi! >> >> It seems that we have a bunch of users whose sAMAccountName and >> userPrincipalName fields contain space characters. This is a mistake that >> was >> caused by some serious cut 'n paste work done by our user account >> management. >> >> So I need to list all the users whose sAMAccountName contains the space >> character and then fix them. For example the value could be: >> "abc1234 " <- so this is the case mostly, the space is located in the end >> of >> the sAMAccountName >> or >> "abc 1234" <- it could be in the middle >> or >> " abc1234" <- it could be in the start >> >> Does query: >> GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { >> $_.LogonName -like "* *" } >> ... return all the cases listed above? > > Yep, I think this should work. Another way would be: > > PS> ' brat wurst banane '.ToCharArray() -contains ' ' > True > >> If I now have them in the pipeline how can I remove all the spaces from >> the >> sAMAccount -field (so no parsing on Name -field and so on!)? > > PS> $newname = ' brat wurst banane ' -replace ' ','' > PS> $newname > bratwurstbanane > > -- > greetings > dreeschkind Or simply: PS> $newname = ' brat wurst banane ' -replace '\s' PS> $newname bratwurstbanane -Hecks |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Listing out all usernames with space Marco Shaw wrote: > Kari wrote: >> Hi! >> >> It seems that we have a bunch of users whose sAMAccountName and >> userPrincipalName fields contain space characters. This is a mistake >> that was caused by some serious cut 'n paste work done by our user >> account management. >> >> So I need to list all the users whose sAMAccountName contains the >> space character and then fix them. For example the value could be: >> "abc1234 " <- so this is the case mostly, the space is located in the >> end of the sAMAccountName >> or >> "abc 1234" <- it could be in the middle >> or >> " abc1234" <- it could be in the start >> >> Does query: >> GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object >> { $_.LogonName -like "* *" } >> ... return all the cases listed above? >> >> If I now have them in the pipeline how can I remove all the spaces >> from the sAMAccount -field (so no parsing on Name -field and so on!)? Sorry, I skipped over the part where you also wanted to *fix* the spaces... Others have answered by now... |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Listing out all usernames with space > > PS> $newname = ' brat wurst banane ' -replace ' ','' > > PS> $newname > > bratwurstbanane > > > > -- > > greetings > > dreeschkind > > Or simply: > > PS> $newname = ' brat wurst banane ' -replace '\s' > PS> $newname > bratwurstbanane > > -Hecks Ok. But how to put this in action? Let's say that I query the users first to the pipeline or save them like this: $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { $_.LogonName -like "* *" } | select-object logonname How should I run the replace on this array? I tried with one test user (one user object stored in the $spaceusers: $spaceusers -replace '\s' .... and it just returns "@{LogonName=xyz8976} but doesn't actually modify anything. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Listing out all usernames with space > Ok. But how to put this in action? > > Let's say that I query the users first to the pipeline or save them like this: > $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | > Where-Object { $_.LogonName -like "* *" } | select-object logonname > > How should I run the replace on this array? I tried with one test user (one > user object stored in the $spaceusers: > $spaceusers -replace '\s' > > ... and it just returns "@{LogonName=xyz8976} but doesn't actually modify > anything. So this probably does the trick for the array, but how can I commit the changes from the modified array back to LDAP? Is it wise to handle these as objects all the way? |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Listing out all usernames with space "Kari" <Kari@discussions.microsoft.com> wrote in message news 63D867E-8CA2-4F6A-B9A8-CF95360C13E5@microsoft.com...>> Ok. But how to put this in action? >> >> Let's say that I query the users first to the pipeline or save them like >> this: >> $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | >> Where-Object { $_.LogonName -like "* *" } | select-object logonname >> >> How should I run the replace on this array? I tried with one test user >> (one >> user object stored in the $spaceusers: >> $spaceusers -replace '\s' >> >> ... and it just returns "@{LogonName=xyz8976} but doesn't actually modify >> anything. > > So this probably does the trick for the array, but how can I commit the > changes from the modified array back to LDAP? Is it wise to handle these > as > objects all the way? Try adding the replace action to the pipeline, like so: $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { $_.LogonName -like "* *" } | select-object logonname | Foreach-Object {$_.logonname -replace "\s"} which is equivalent to:: $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Where-Object { $_.LogonName -like "* *" } | select-object logonname $spaceusers = $spaceusers | % {$_.logonname -replace "\s"} You could probably get away with leaving out the Where-Object part of the pipeline, depending on the object emitted by GeQADUser. Maybe: $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | Foreach-Object { $_.LogonName -replace "\s" } Sorry, I can't help you with the second question! -Hecks |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Listing out all usernames with space > Try adding the replace action to the pipeline, like so: > > $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | > Where-Object { $_.LogonName -like "* *" } | select-object logonname | > Foreach-Object {$_.logonname -replace "\s"} > > which is equivalent to:: > > $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | > Where-Object { $_.LogonName -like "* *" } | select-object logonname > > $spaceusers = $spaceusers | % {$_.logonname -replace "\s"} > > You could probably get away with leaving out the Where-Object part of the > pipeline, depending on the object emitted by GeQADUser. Maybe: > > $spaceusers = GetQADUser -SearchRoot "mydomain.local/ou" -SizeLimit 0 | > Foreach-Object { $_.LogonName -replace "\s" } > > Sorry, I can't help you with the second question! > > -Hecks > Let's say that I have an user named "Mickey Mouse" whose username is "mickey1 ". Now if I want to query for Mickey Mouse and change his username to "mickey1" it would be done like this: GetQADUser -name 'Mickey Mouse' -SizeLimit 0 |select-object logonname | Foreach-Object {$_.logonname -replace "\s"} So now I finally have an answer. Thank you! |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Listing out all usernames with space "Kari" wrote: > Let's say that I have an user named "Mickey Mouse" whose username is > "mickey1 ". Now if I want to query for Mickey Mouse and change his username > to "mickey1" it would be done like this: > > GetQADUser -name 'Mickey Mouse' -SizeLimit 0 |select-object logonname | > Foreach-Object {$_.logonname -replace "\s"} > > So now I finally have an answer. Thank you! .... or that's what I thought. That doesn't do anything. If I change Mickeys username to "mickey 1" and run the command above nothing happens except it prints out the username in correct form "mickey1". So how can I apply my changes to LDAP? (it sucks that you can't modify your posts!) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| stored usernames and passwords | Vista General | |||
| How can I hide usernames from Welcome Screen? | Vista General | |||
| Home folders not displaying usernames | Vista General | |||
| passwords and usernames | Vista account administration | |||
| No numeric usernames? | Vista account administration | |||