Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to run though a list of 100 user names and clear their Pager field, can it be done with Power Shell? The input of the file name which includes the user names looks like this: itaig haruth geloos fested

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

If you want/ can use AD Module than this should be no-brainer:

gc cidway.txt | Set-ADUser -Clear pager

Read help:

Get-Help Set-ADUser -Parameter Clear

... for more info.

share|improve this answer
    
Set-ADUser : Cannot find an object with identity: 'ramih ' under: 'DC=asuta,DC=co,DC=il'. At C:\Users\itaig.ASUTA\AppData\Local\Temp\21fb2c52-2bf6-4194-ab99-17713ad6682f.ps1‌​:2 char:30 + gc c:\cidway.txt | Set-ADUser <<<< -Clear pager + CategoryInfo : ObjectNotFound: (ramih :ADUser) [Set-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : Cannot find an object with identity: 'ramih ' under: 'DC=asuta,DC=co,DC=il'.,Microsoft.ActiveDirectory.Manag –  Itai Ganot Jul 30 '12 at 11:10
    
Well, if you have your file wrong (and it looks like it so - mind trailing space) than no command will help you... ;) You can either fix file, or result of gc (e.g. gc | foreach { $_.Trim() } | Set-ADUser –  BartekB Jul 30 '12 at 11:14
    
I've fixed the trailing spaces but receiving the same error: Set-ADUser : Cannot find an object with identity: 'glasshouseusr' under: 'DC=asuta,DC=co,DC=il'. At line:5 char:30 + gc c:\cidway.txt | Set-ADUser <<<< -Clear pager + CategoryInfo : ObjectNotFound: (glasshouseusr:ADUser) [Set-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : Cannot find an object with identity: 'glasshouseusr' under: 'DC=asuta,DC=co,DC=il'.,Microsoft.ActiveDirectory.Management.Commands.SetADUser –  Itai Ganot Jul 30 '12 at 13:03
    
Error is not the same - it stops on different user now. Unless you've changed txt file it means something is really wrong with this particular user identity. Identity can be DN, sAMAccountName, objectGUID or objectSid (Get-Help Set-ADUser -Parameter Identity). Make sure identities in txt file are correct and match any of attributes that I've mentioned and you are good to go. If you are not sure, just try Get-ADUser <youridentity> and see for yourself. :) –  BartekB Jul 31 '12 at 9:55
    
I'm sorry, i missed your last answer but it solved my issue, so thanks. –  Itai Ganot Jul 31 '12 at 16:50
add comment

You mean a script?

Something along:

Const ADS_PROPERTY_CLEAR = 1 
foreach ($usr in Get-Content “C:\file.txt”)
{
Set objUser = GetObject _
   ("LDAP://cn="+$usr", ou=finance, dc=fabrikam, dc=com") 

objUser.PutEx ADS_PROPERTY_CLEAR, "pageNumber", 0
objUser.SetInfo
}
share|improve this answer
    
Yes i meant a script in Power Shell, something like this: Get-Content c:\cidway.txt | foreach-object { set-aduser -identity $_ -clear pager } –  Itai Ganot Jul 29 '12 at 7:27
    
Well here's a script, if you want a one liner, I can't really help you atm :) –  Lucas Kauffman Jul 29 '12 at 7:28
    
Can anyone show me how it should be done in Power Shell? –  Itai Ganot Jul 29 '12 at 9:12
    
This is a powershell script... –  Lucas Kauffman Jul 29 '12 at 9:18
    
but it's not working :( –  Itai Ganot Jul 29 '12 at 9:27
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.