【发布时间】:2022-09-27 09:28:44
【问题描述】:
我有一个适用于所有其他属性的脚本。我不明白如何做到这一点。我是脚本新手。在添加 msDS-cloudExtensionAttribute1 之前,我的导入效果很好。我还需要添加几个。感谢您的浏览。
#Import active directory module for running AD cmdlets
Import-Module ActiveDirectory
#Store the data from ADUsers.csv in the $ADUsers variable
$Users = Import-csv C:\\Test\\TESTUSER3a.csv
#Loop through each row containing user details in the CSV file
foreach ($User in $Users)
{
# Read user data from each field in each row
# the username is used more often, so to prevent typing, save that in a variable
$Username = $User.SamAccountName
}
# Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username}) {
#If user does exist, give a warning
Write-Warning \"A user account with username $Username already exist in Active Directory.\"
}
else {
# User does not exist then proceed to create the new user account
# create a hashtable for splatting the parameters
$userProps = @{
SamAccountName = $User.SamAccountName
Path = $User.path
GivenName = $User.GivenName
Surname = $User.Surname
Initials = $User.Initials
Name = $User.Name
DisplayName = $User.DisplayName
UserPrincipalName = $user.UserPrincipalName
Department = $User.Department
Description = $User.Description
Office = $User.Office
OfficePhone = $User.OfficePhone
EmailAddress = $User.EmailAddress
StreetAddress = $User.StreetAddress
POBox = $User.POBox
City = $User.City
State = $User.State
PostalCode = $User.PostalCode
Title = $User.Title
Company = $User.Company
\"msDS-cloudExtensionAttribute1 = GGGG\" = $User.GGGG
# AccountPassword = (ConvertTo-SecureString $User.password -AsPlainText -Force)
Enabled = $false
ChangePasswordAtLogon = $false
} #end userprops
}
New-ADUser @userProps
Write-Host \"The user account $User is created.\" -ForegroundColor Cyan
#end else
标签: powershell azure-active-directory