Hey all,<\/p>\n
I have been going nuts trying to figure this out. I am trying to put together a script to create a local user account on a remote machine (a server) and set properties on the account. In my testing, I have managed to get an account created LOCALLY but when pointing to the remote computer, it doesnt work<\/p>\n
I am a novice to powershell so the script below may not look very efficient in the use of commands/variables but it works (locally). Essentially, the username and the password is to be the mac address of the wifi adapter - the full name is to be the laptop model and the description its asset tag barcode # - the first 6 lines defines the barcode# and model<\/p>\n
$computername = $env:computername\n$newcontent = $computername.replace(($computername.substring(0,3)),\"0000\") \n$barcode= $newcontent -replace \".{4}$\"\n\n$model = wmic csproduct get name\n$model2 = $model -replace'.*?(?=.{1,7}$)'\n$model3 = $model2 -replace \"\\s+\", \"\"\n\n$mac = get-wmiobject win32_networkadapter | Where-Object {$_.Name -match \"wireless\"} | Select-Object MACAddress -unique | foreach {$_.MacAddress -replace \":\",\"\"} \n$mac = $mac.tolower()\n$UserName=\"$mac\"\n$Password=\"password123\"\n$Computer = [ADSI]\"WinNT://$Env:the_computer_name\" \n\nnet user $UserName $Password /add /active:yes /comment:$barcode /fullname:$model3\nwmic useraccount where \"name='$UserName'\" set PasswordExpires=false\nwmic useraccount where \"name='$UserName'\" set PasswordChangeable=false\nnet localgroup testgroup $mac /add\n\n<\/code><\/pre>","upvoteCount":2,"answerCount":5,"datePublished":"2019-02-08T16:15:52.000Z","author":{"@type":"Person","name":"dexterit","url":"https://community.spiceworks.com/u/dexterit"},"suggestedAnswer":[{"@type":"Answer","text":"Hey all,<\/p>\n
I have been going nuts trying to figure this out. I am trying to put together a script to create a local user account on a remote machine (a server) and set properties on the account. In my testing, I have managed to get an account created LOCALLY but when pointing to the remote computer, it doesnt work<\/p>\n
I am a novice to powershell so the script below may not look very efficient in the use of commands/variables but it works (locally). Essentially, the username and the password is to be the mac address of the wifi adapter - the full name is to be the laptop model and the description its asset tag barcode # - the first 6 lines defines the barcode# and model<\/p>\n
$computername = $env:computername\n$newcontent = $computername.replace(($computername.substring(0,3)),\"0000\") \n$barcode= $newcontent -replace \".{4}$\"\n\n$model = wmic csproduct get name\n$model2 = $model -replace'.*?(?=.{1,7}$)'\n$model3 = $model2 -replace \"\\s+\", \"\"\n\n$mac = get-wmiobject win32_networkadapter | Where-Object {$_.Name -match \"wireless\"} | Select-Object MACAddress -unique | foreach {$_.MacAddress -replace \":\",\"\"} \n$mac = $mac.tolower()\n$UserName=\"$mac\"\n$Password=\"password123\"\n$Computer = [ADSI]\"WinNT://$Env:the_computer_name\" \n\nnet user $UserName $Password /add /active:yes /comment:$barcode /fullname:$model3\nwmic useraccount where \"name='$UserName'\" set PasswordExpires=false\nwmic useraccount where \"name='$UserName'\" set PasswordChangeable=false\nnet localgroup testgroup $mac /add\n\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2019-02-08T16:15:53.000Z","url":"https://community.spiceworks.com/t/help-needed-creating-new-user-on-remote-machine/696737/1","author":{"@type":"Person","name":"dexterit","url":"https://community.spiceworks.com/u/dexterit"}},{"@type":"Answer","text":"If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>