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"

4 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!

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More