Skip to content

Instantly share code, notes, and snippets.

@Erreinion
Created July 17, 2013 17:19
Show Gist options
  • Save Erreinion/6022554 to your computer and use it in GitHub Desktop.
Save Erreinion/6022554 to your computer and use it in GitHub Desktop.
Remotely rename local account names, array iteration,
$comps = @("comp2", "comp1")
$comps | Foreach {
if(Test-Connection $_ -q -count 1){
$user = Get-WMIObject Win32_UserAccount -computername $_ -Filter "Name='@oldname'"
$result = $user.Rename('@newname')
if ($result.ReturnValue -eq 0) {
return Get-WMIObject Win32_UserAccount -computername $_ -Filter "Name='@newname'"
}
}
else{
Write-Host "$_ Not found" -fore red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment