简体   繁体   中英

Import users to local with powershell windows server 2008 r2

I got this script:

$Users = Import-Csv C:\Users\Administrator\Desktop\userImport\userTest.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 ("SERVER02\Users")
$userGroup.Add($createUser.Path)
}

But I get the error: A member could not be added to or removed from the local group because the member does not exist. How Can I possible fix it??

try changing the . with the computer name here:

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

as

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM