我得到了下面的代碼(工作):PowerShell的存在本地用戶ADSI
#Import File
$Users = Import-Csv C:\Users\Administrator\Desktop\userImport\users.csv
# Setting data
$compname = hostname
$computer = [ADSI]"WinNT://$compname"
$userGroup = [ADSI]"WinNT://./Users,Group"
# Loop to add all users
$Users | % {
# Create user itself
$createUser = $computer.Create("User",$_.userid)
# Set password (print1!)
$createUser.SetPassword($_.password)
$createUser.SetInfo()
# Create extra data
$createUser.Description = "Import via powershell"
$createUser.FullName = $_.'full name'
$createUser.SetInfo()
# Set standard flags (Password expire/Password change/Account disabled)
$createUser.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
$createUser.SetInfo()
# Adduser to standard user group ("SERVER02\Users")
$userGroup.Add($createUser.Path)
# Show that user X as been added
$username = $_.'full name'
echo "User $username added"
}
但怎麼可能,如果用戶已經存在建立一個檢查? 在網絡上我真的不能找到什麼:X
已存在的組或作爲本地用戶? –
如果用戶已經以本地用戶身份 –