Powershell遷徙域用戶的屬性值

最近同事在忙域用戶的遷徙。今天早上他給了我個已經遷徙了的名單,讓我幫忙寫個簡單的腳本,從一個csv文件裏面讀取用戶的名字,然後從域 A裏面獲取extensionattribute10的值,寫入另外一個域B 裏面對應的用戶屬性裏,然後把該用戶從A裏的某個用戶組裏刪掉。


我的基本思路很簡單,在域A裏面讀取C文件,把用戶名字放入數組,然後循環讀取每一個名字,查找對應的屬性值,輸出到文本D,順便把該用戶從對應的組裏面刪掉。



$db=get-contentc:\users\yuan.li.mitch\desktop\test.log


foreach( $data in $db) {

$Attribute=get-AdUser $data -properties extensionattribute10

$data + ","+ $Attribute.extensionattribute10 >> .\user.csv

remove-adgroupmember-identity "group.citrix.mozilla" -members $name –confirm:false

}


然後在域B裏面讀取文本D,更改對應的數據,然後再確認一下是否都更改了


#############Update######################


$db=Get-ContentC:\temp\users.csv

foreach ( $data in $db) {

$namesplit=$data.Split(",")

$username=$namesplit[0]+"."+$namesplit[1]

$cardnumber=$namesplit[2]

set-aduser $username -add@{extensionattribute10=$cardnumber}


}



###############Confirm#####################


$db=Get-ContentC:\temp\users.csv


foreach ( $data in $db) {

$namesplit=$data.Split(",")

$username=$namesplit[0]+"."+$namesplit[1]

$cardnumber=$namesplit[2]


try{

$att=get-aduser $username-properties extensionattribute10


if ($att.extensionattribute10-eq $cardnumber){


write-host "succesful"


}

else

{

write-host "failed"

$username  >>c:\temp\logs\list.txt

}


}

Catch

{$_ | Out-FileC:\temp\logs\errors.txt -Append

}

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章