Rename-Computer Script without psw window? RRS feed

  • Question

  • Hi everybody 

    I made a little script to rename computers (windows 7 Pro), and it works, is very simple 
    first i create a file .CSV with the oldname and newname
    then, im using the following lines is how i change the pc name 

    $a = Import-Csv ServerNames.csv -Header OldName, NewName

    Foreach ( $Server in $a ) {Rename-Computer -ComputerName $Server.OldName -NewName $Server.NewName -LocalCredential localhost\localuser -DomainCredential Domain\UserDomain -Force -Restart}

    but i need write the psw in the powershell credential window, with each of the computers and my question, is possible to add the psw for the localuser and the domainuser in the script to avoid write it?

    sorry for the noob question
    thanks in advance

    Wednesday, August 30, 2017 2:27 AM

All replies

  • PSW?

    Does that mean "password".

    First learn how to format and post code so that it is readable by use stupid technical people.  We are not hip-hop cool and cannot decode your street talk.

    $local = Get-Credential localhost\localuser
    $domain = Get-Credential Domain\UserDomain
    Import-Csv ServerNames.csv -Header OldName, NewName |
    		Rename-Computer -ComputerName $_.OldName -NewName $_.NewName -LocalCredential $local -DomainCredential $domain -Force -Restart 

    This would do the trick but you may have other issues.


    Wednesday, August 30, 2017 2:36 AM