MikeDouglasDev MikeDouglasDev - 4 months ago 29
Powershell Question

Windows Server 2012 RC PowerShell Error: Exception calling "SetInfo" with "0" argument(s): "The specified network

I'm trying to run the following PowerShell script to create a local user. This works in Windows Server 2008 R2 but I'm getting the error below on Windows Server 2012 RC. Any ideas on how to make this work in Windows Server 2012 RC?

$ComputerName = 'localhost'
$computer = [ADSI]"WinNT://$ComputerName"
$user = $computer.Create("User","Test")
$user.setpassword("P2ssw0rd")
$user.put("fullname","Test User")
$user.SetInfo()
$User.UserFlags[0] = $User.UserFlags[0] -bor 0x10000 #ADS_UF_DONT_EXPIRE_PASSWD flag is 0x10000
$User.SetInfo()


Error Message:
Exception calling "SetInfo" with "0" argument(s): "The specified network
password is not correct.

I also found someone on Technet with the same issue. No answer there.
http://social.technet.microsoft.com/Forums/en/ITCG/thread/16b0f6cc-1c85-4a6f-ba4f-1515f2991bec

Thanks,
Mike

Answer

Thanks to someone on the Technet forum, the answer is to not use localhost for the computername. Here is the updated code.

$ComputerName = $env:ComputerName 
$computer = [ADSI]"WinNT://$ComputerName"

Hope it helps others.

Thanks, Mike

Comments