Monday, May 20, 2013

Home /PowerShell /script / Stamp a value in an Attribute–PowerShell Script

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)"

SS

Santhosh Sivarajan

Microsoft MVP · Identity & Cybersecurity Architect

Santhosh has 30+ years of hands-on enterprise experience in Identity and Access Management, Microsoft Entra ID, Active Directory, Microsoft 365 and Zero Trust architecture. He is the author of two books on Windows Server and security, and leads consulting, assessments and training at SAG Business Group.

1 comments:

Okay, I will check it out later. Thanks for sharing this info!

Post a Comment

Popular Posts