Hello,
We are working with moving a number of our virtual servers and once the migration is completed for each server, the server is not on the domain so local admin access is required to get it back on the domain. To that end I want to add a local user account to these servers that is in the administrator group. I've found a post that's getting me half-way there...it allows me to create a local user via Powershell (I'm using version 3) on my computer (localhost), but when I try to do this to a remote server where I do have administrative priviledges it says the local user account already exists (I think it's ignoring the remote server name and only looking at my local computer).
Any tips, ideas on how I can take this code to read through an input list of servers and add a local user id (that is Admin and has a password that never expires) to those servers. I'd prefer to not have to run this as a function but to load up the script in Powershell ISE. I'll hardcode in the username and password in the script instead.
function create-user($username, $password) { $computer = [ADSI]“WinNT://serverA” foreach ($user in $computer.psbase.children) { if ($user.Name -eq $username) { Write-Host $user.Name “already exist.” Return } } $user_obj = $computer.Create(“user”, “$username”) $user_obj.Put(“description”, “$username”) $user_obj.SetInfo() $user_obj.SetPassword($password) $user_obj.SetInfo() $user_obj.psbase.invokeset(“AccountDisabled”, “False”) $user_obj.SetInfo() if ($user.Name -eq $username) { Write-Host “$username created.” Return } else { Write-host “Error Creating $username” } }Thank you.