我的人力資源部門向我提供了幾千名具有更新的「公司」和「地點」字段的用戶列表。我想以此文件爲基礎清理AD。 我必須在名稱上做一些「軟匹配」,因爲我不確定所有名稱都匹配100%。 我該如何解決這個問題?使用CSV作爲輸入清理AD
淑娜,挪威:)
我的人力資源部門向我提供了幾千名具有更新的「公司」和「地點」字段的用戶列表。我想以此文件爲基礎清理AD。 我必須在名稱上做一些「軟匹配」,因爲我不確定所有名稱都匹配100%。 我該如何解決這個問題?使用CSV作爲輸入清理AD
淑娜,挪威:)
如果您使用的是Windows 2008服務器,它包含一個適用於PowerShell的本機AD管理模塊。所以你不需要Quest包。
import-module activedirectory
$users = import-csv path file.txt
foreach($user in $users)
{
set-aduser -id "$($user.name)*" --replace @{Company=$user.Company;physicalDeliveryOfficeName=$user.location}
}
這的確假設您要將位置信息寫入用戶和計算機的「辦公室」字段。 ID上的*應該進行軟搜索。
我會用Quest ActiveRoles Server PowerShell CmdLets。檢查出Get-QADUser examples。
$updates = Import-Csv updates.txt
foreach ($update in $updates) {
$user = Get-QADUser -SamAccountName $update.SamAccountName
$user.Company = $update.Company
# Location is not an attribute of the user
#$user.Location = $update.Location
}
謝謝你們兩位。 我沒有,但具有以下完整的腳本結束(希望這可以利用別人):
Clear-Host
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction silentlycontinue
Add-PSSnapin quest.activeroles.admanagement -ErrorAction silentlycontinue
$file = "\Scripts\employees.csv" # Location of the input file
$file2 = "\Scripts\employees2.csv" # Temp file
$logfile = "\Scripts\logfile.txt" # log file
remove-item $logfile -Force -ErrorAction SilentlyContinue
Get-Content $file | Out-File -Encoding UTF8 $file2 # Convert to UTF8 (we don't touch the original inputfile)
$ListEmployees = Import-Csv $file2 -Delimiter ";" # Import the file to CSV
foreach ($ListEmployee in $ListEmployees) {
$ListDisplayName = $ListEmployee.firstname + " " + $ListEmployee.lastname
if($ADemployee = Get-QADUser -displayname $ListDisplayName -IncludedProperties employeeid)
{
## CHECK NAME
if($($ADEmployee.displayname) -eq $($ListDisplayName))
{
echo "MATCH: $($ADEmployee.displayname)"
}
## CHECK COMPANY
if($($ADEmployee.company) -ne $($ListEmployee.company))
{
echo " CHANGE - Company: '$($ADEmployee.company)' to '$($ListEmployee.company)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -Company $($ListEmployee.company) -WhatIf
}
else
{
echo " OK - Company : no change '$($ListEmployee.company)'"
}
## CHECK OFFICE
if($($ADEmployee.office) -ne $($ListEmployee.office))
{
echo " CHANGE - Office '$($ADEmployee.office)' to '$($ListEmployee.office)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -Office $($ListEmployee.Office) -WhatIf
}
else
{
echo " OK - Office : no change '$($ListEmployee.office)'"
}
## CHECK MOBILE
if($listemployee.mobile -match '\S')
{
if($($ADEmployee.mobile) -ne $($ListEmployee.mobile))
{
echo " CHANGE - Mobile : '$($ADEmployee.mobile)' to '$($ListEmployee.mobile)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -Mobile $($ListEmployee.mobile) -WhatIf
}
else
{
echo " OK - Mobile : no change '$($ListEmployee.mobile)'"
}
}
## CHECK EMPLOYEEID
if($($ADEmployee.employeeid) -ne $($ListEmployee.employeeid))
{
echo " CHANGE - EmployeeID: '$($ADEmployee.employeeid)' to '$($ListEmployee.employeeid)'"
Set-QADUser -identity $($ADEmployee.samaccountname) -ObjectAttributes @{employeeID = $($ListEmployee.employeeid)} -WhatIf
}
else
{
echo " OK - EmployeeID : no change '$($ListEmployee.employeeid)'"
}
$match++
}
else
{
if($EXContact = Get-Contact $ListDisplayName -ErrorAction SilentlyContinue)
{
echo "MATCH CONTACT: $ListDisplayName (contact)"
## CHECK MOBILE
if($listemployee.mobile -match '\S')
{
if($($EXContact.Mobilephone) -ne $($ListEmployee.mobile))
{
echo " CHANGE - Mobile : '$($EXContact.Mobilephone)' to '$($ListEmployee.mobile)'"
}
else
{
echo " OK - Mobile ; No change ($($ListEmployee.mobile))"
}
}
## CHECK COMPANY
if($($EXContact.company) -ne $($ListEmployee.company))
{
echo " CHANGE - Company: '$($EXContact.company)' to '$($ListEmployee.company)'"
}
else
{
echo " OK - Company : No change($($ListEmployee.company))"
}
## CHECK OFFICE
if($($EXContact.office) -ne $($ListEmployee.office))
{
echo " CHANGE - Office '$($EXContact.office)' to '$($ListEmployee.office)'"
}
else
{
echo " OK - Office : No Change($($ListEmployee.office))"
}
$contactmatch++
}
else
{
echo "$ListDisplayName" | Out-File $logfile -Append
echo "NO MATCH: $ListDisplayName"
$nomatch++
}
}
$i++
}
echo " "
echo "List contains $i accounts"
echo "Accounts: $match matches"
echo "Contacts: $contactmatch"
echo "No Match: $nomatch"
所以你就想到smebody爲你做了嗎?你到目前爲止嘗試了什麼? – JPBlanc
你當然是正確的JPBlanc。我不應該指望有人爲我做這件事:)我不是。我只是在尋找一些起點來驗證我是否已經開始朝着正確的方向發展(或不是)。我一回到辦公室就會發布我的腳本塊。 – Sune