次のコードを取得しました(動作):
#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