Monday, May 20, 2013

Stamp a value in an Attribute–PowerShell Script

You can use this PowerShell Script to stamp a value in an attribute.  Int he  below example, I am stamping DoNotSync value in altSecurityIdentities attribute. 

Script

#
# Author - Santhosh Sivarajan
# Version 1.0

Clear
$N = 0
$migValue = "DoNotSync"
Import-CSV C:\Scripts\input.csv | % {
#input.csv contains sAMAccountName.  Header must be UserName
    $UserN = $_.UserName
    $ObjFilter = "(&(objectCategory=person)(objectCategory=User)(samaccountname=$UserN))"
    $objSearch = New-Object System.DirectoryServices.DirectorySearcher
    $objSearch.PageSize = 15000
    $objSearch.Filter = $ObjFilter 
    $objSearch.SearchRoot = "LDAP://dc=sivarajan,dc=com"
    $AllObj = $objSearch.findOne()
    $user = [ADSI] $AllObj.path
    Write-host -NoNewLine "Updating.... $UserN"
    $user
    $user.psbase.invokeSet("altSecurityIdentities",$migValue)
    $user.setinfo()
    Write-host "Done!"
    $N ++
    }
   
Write-host "Udpated $N User Account(s)"

0 comments:

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More