Thursday, May 16, 2013

Copy Attribute Values–PowerShell Script

This can be used to copy a value from one attribute to another.  In the below example, I am coping Exchange Alias (mailnickname) value to extensionattribute14

Script:

#
# Author - Santhosh Sivarajan
# Version 1.0
Clear
$N = 0
$UserInfoFile = New-Item -type file -force "D:\Scripts\UserInfo.txt"
"distinguishedName`tAlias" | Out-File $UserInfoFile -encoding ASCII
$ObjFilter = "(&(objectCategory=person)(objectCategory=User)(mail=*)(!extensionAttribute14=*))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 15000
$objSearch.Filter = $ObjFilter 
$objSearch.SearchRoot = "LDAP://DC=sivarajan,DC=com"
$AllObj = $objSearch.FindAll()
    foreach ($Obj in $AllObj)
    {   
        $user = [ADSI] $Obj.path
        $objItemT = $Obj.Properties
        $tAlias = $objItemT.mailnickname
        $tUDN =  $objItemT.distinguishedname
        Write-host -NoNewLine "Updating.... $tUDN"
        $user.psbase.invokeSet("extensionattribute14","$tAlias")
        $user.setinfo()
        "$tUDN`t$tAlias" | Out-File $UserInfoFile -encoding ASCII -append
        Write-host "Done!"
        $N ++   
    }

Write-host "Successfully updated $N user obejcts.  Please reveiw $UserInfoFile for more information"

6 comments:

I will learn more about this script. I might use it in the future. Bye!

Lots of interesting information on this site https://best-writing-service.com/thesis. I always visit him. If you are a student you will find many interesting things there. I showed it to all my friends.

Best Assignment Help Online has been a frequent provider of online services in the US and other countries for more than five years. Help Me Do My Homework

Hyvää päivänjatkoa, rakkaat ystävät. Jos sinulla on ongelmia sukupuolielinten kanssa, - neuvoisin sinua aloittamaan lääkityksen viagra netistä, - joka varmasti auttaa sinua, aivan kuten minäkin!

ABC Assignment help is ready to provide best physics assignment help for those students, who have trust on our assignment help due to our amazing features like, plagiarism free content, after sales service, 24*7 support and error free papers, etc.

ABC Assignment Help is an incomparable online Engineering assignment help company delivering excellent academic assignments, essays, coursework and reports. Through a team of over 3000 subject experts we ensure individual attention to every student making the assignment help experience completely personalized in nature. With our round the clock services, you can be assured of high grades every time.

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More