Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, October 15, 2016 12:32 PM
Greetings,
I am about to change over 100 Domain computer names in our organization and would like to do it through Powershell.
I found an script that changes the computer name with csv file but i am not able to get it going :/
function ComputerExists ($sam) { [bool]([adsisearcher]"(sAMAccountName=$sam$)").FindOne() }
$csvfile = "C:\temp\rename.csv"
$csv = Import-Csv $csvfile
foreach ($c in $csv) {
$oldName = $c.oldName
$newName = $c.newName
if (-not(ComputerExists $newName)) {
Write-Host "Renaming computer from: $oldName to: $newName"
netdom renamecomputer $oldName /newName:$newName /uD:domain\user /passwordD:"" /force
}
else { Write-Host "$newName already exists" }
}
I am getting error message
Renaming computer from: to:
The parameter /newName was unexpected.
The syntax of this command is:
NETDOM [ ADD | COMPUTERNAME | HELP | JOIN | MOVE | QUERY | REMOVE |
MOVENT4BDC | RENAMECOMPUTER | RESET | TRUST | VERIFY | RESETPWD ]
Try "NETDOM HELP" for more information.
I appreciate all help!
Thanks!
All replies (2)
Saturday, October 15, 2016 1:35 PM âś…Answered
Case closed got it resolved. Found a new script
$cred = get-credential
$Computers = import-csv c:\temp\rename.csv
foreach ($Computer in $Computers){
Rename-Computer -NewName $Computer.NewName -ComputerName $Computer.Name -DomainCredential $cred -Restart
}
Saturday, October 15, 2016 1:03 PM
Greetings Richard,
Thank you for replying back to me.
My CSV file looks like this -
"$OldName,$NewName"
"PXE,PXEE" This is only a test computer