Powershell - 通过 csv 更新 AD 属性

问题描述 投票:0回答:0

我们尝试将一个应用程序集成到 AD,在第 1 阶段中,我们尝试使现有的 AD 信息与从应用程序到 AD 的现有数据同步。

我们唯一的共同点是电子邮件地址,因此使用 UPN。

下面是我的代码,但没有任何错误,广告也没有反映更改。

CSV 文件标题如下匹配 AD 属性。

# Import data from CSV file
$users = Import-Csv -Path 'C:\Temp\myhr\Upload-myhr2.csv'

# Iterate over each row of data
$users | ForEach-Object {
    # Get user principal name and manager from current row
    $supn = $_.Mail
    $supnmgr = $_.Manager

    # Check if user principal name is not in not found list
    if (!$notfound.Contains($supn)) {
        # Get distinguished name and manager of user
        $DN = Get-ADUser -Filter { UserPrincipalName -eq $supn } -Properties * | Select-Object -ExpandProperty DistinguishedName
        $mgr = Get-ADUser -Filter { UserPrincipalName -eq $supnmgr }

        # Update properties of user
        Set-ADUser $DN -EmployeeID $_.EmployeeID -GivenName $_.FirstName -Surname $_.LastName -Manager $mgr -Department $_.Department -Title $_.Title -Company $_.Company -StreetAddress $_.StreetAddress -PostOfficeBox $_.PostOfficeBox -City $_.City -State $_.State -PostalCode $_.PostalCode -Country $_.Country -ExtensionAttribute5 $_.ExtensionAttribute5 -ExtensionAttribute6 $_.ExtensionAttribute6 -ExtensionAttribute7 $_.ExtensionAttribute7 -ExtensionAttribute9 $_.ExtensionAttribute9
    }
}

尝试使用 1 个帐户和虚拟数据,没有任何变化。

我的 csv 标题如下;

mail,employeeID,GivenName,Surname,DisplayName,title,telephoneNumber,manager,extensionAttribute6,extensionAttribute7,company,department,extensionAttribute5,extensionAttribute9,StreetAddress ,postOfficeBox,l,st,postalCode,co
[email protected],Test Employee ID,Test First Name,Test Last Name,First Last,test titile,12345,[email protected],Test Job Family,Test Divison,Test company,Test Department,Test sub location,Test Cost Centre,Test Street,Test Post Box,Test Location,Test State,Test Postal Code,Singapore
powershell active-directory
© www.soinside.com 2019 - 2024. All rights reserved.