Created
July 17, 2013 17:19
-
-
Save Erreinion/6022554 to your computer and use it in GitHub Desktop.
Remotely rename local account names, array iteration,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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