我得到以下代码(工作):
#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