使用 Powershell Windows Server 2008 r2 将用户导入本地



我得到了这个脚本:

$Users = Import-Csv C:UsersAdministratorDesktopuserImportuserTest.csv
$Users | % { 
# Setting data
$computer = [ADSI]"WinNT://."
$userGroup = [ADSI]"WinNT://./Users,Group"
# 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 ("SERVER02Users")
$userGroup.Add($createUser.Path)
}

但是我得到错误:无法在本地组中添加或删除成员,因为该成员不存在。我怎么可能修复它?

尝试在此处使用计算机名称更改.

$computer = [ADSI]"WinNT://."

$compname = hostname
$computer = [ADSI]"WinNT://$compname"

最新更新