AD 用户的个人密码 |通过 CSV 导入
Individual passwords for AD user | Import via CSV
我正在尝试通过 CSV/PowerShell 将用户导入 AD。
现在导入工作正常,用户和所有属性都正确,但似乎密码没有从我的 .csv 中正确导入。
这是我的 .ps1 我正在使用:
#Import required modules
Import-Module ActiveDirectory
#Prompt user for CSV file path
$filepath = Read-Host -Prompt "Enter Path of CSV"
$securePassword = ConvertTo-SecureString $pass -AsPlainText -Force
# Import the file into a variable
$users = Import-Csv $filepath -Delimiter ";"
#Loop through each row and gather information
ForEach ($user in $users) {
#Gather the user's information
$fname = $user.FirstName
$lname = $user.LastName
$uname = $user.Username
$email = $user.Email
$jtitle = $user.Title
$OUpath = $user.'Organizational Unit'
$pass = $user.Password
$SAM = $user.SAM
#Create new AD user for each user in CSV file
New-ADUser -Name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincipalName $uname -SamAccountName $SAM -Path $OUpath -AccountPassword $securePassword -PasswordNeverExpires $true -Enabled $true -EmailAddress $email
# Echo for every user created
}
有人知道这里的原因是什么吗?
谢谢,
马吕斯
在从 csv 导入之前,您正在将 $pass 转换为安全字符串。所以固定的:
#Import required modules
Import-Module ActiveDirectory
#Prompt user for CSV file path
$filepath = Read-Host -Prompt "Enter Path of CSV"
# Import the file into a variable
$users = Import-Csv $filepath -Delimiter ";"
#Loop through each row and gather information
ForEach ($user in $users) {
#Gather the user's information
$fname = $user.FirstName
$lname = $user.LastName
$uname = $user.Username
$email = $user.Email
$jtitle = $user.Title
$OUpath = $user.'Organizational Unit'
$pass = $user.Password
$SAM = $user.SAM
$securePassword = ConvertTo-SecureString $pass -AsPlainText -Force
# The Rest
我正在尝试通过 CSV/PowerShell 将用户导入 AD。 现在导入工作正常,用户和所有属性都正确,但似乎密码没有从我的 .csv 中正确导入。
这是我的 .ps1 我正在使用:
#Import required modules
Import-Module ActiveDirectory
#Prompt user for CSV file path
$filepath = Read-Host -Prompt "Enter Path of CSV"
$securePassword = ConvertTo-SecureString $pass -AsPlainText -Force
# Import the file into a variable
$users = Import-Csv $filepath -Delimiter ";"
#Loop through each row and gather information
ForEach ($user in $users) {
#Gather the user's information
$fname = $user.FirstName
$lname = $user.LastName
$uname = $user.Username
$email = $user.Email
$jtitle = $user.Title
$OUpath = $user.'Organizational Unit'
$pass = $user.Password
$SAM = $user.SAM
#Create new AD user for each user in CSV file
New-ADUser -Name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincipalName $uname -SamAccountName $SAM -Path $OUpath -AccountPassword $securePassword -PasswordNeverExpires $true -Enabled $true -EmailAddress $email
# Echo for every user created
}
有人知道这里的原因是什么吗?
谢谢, 马吕斯
在从 csv 导入之前,您正在将 $pass 转换为安全字符串。所以固定的:
#Import required modules
Import-Module ActiveDirectory
#Prompt user for CSV file path
$filepath = Read-Host -Prompt "Enter Path of CSV"
# Import the file into a variable
$users = Import-Csv $filepath -Delimiter ";"
#Loop through each row and gather information
ForEach ($user in $users) {
#Gather the user's information
$fname = $user.FirstName
$lname = $user.LastName
$uname = $user.Username
$email = $user.Email
$jtitle = $user.Title
$OUpath = $user.'Organizational Unit'
$pass = $user.Password
$SAM = $user.SAM
$securePassword = ConvertTo-SecureString $pass -AsPlainText -Force
# The Rest