MikeDouglasDev MikeDouglasDev - 1 year ago 249
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.put("fullname","Test User")
$User.UserFlags[0] = $User.UserFlags[0] -bor 0x10000 #ADS_UF_DONT_EXPIRE_PASSWD flag is 0x10000

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.


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download