Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Powershell Tool in Inventory - Rename domain joined computer

Hi wondering if its possible to have a pop-up screen that takes a new hostname into a variable that then gets passed to a powershell command.


Rename-Computer -NewName (Variable) -force -restart Variable = popup entry??



Date Votes
  • get-item cert:\LocalMachine\My\* | remove-item
    $SN = gwmi win32_bios | select -ExpandProperty SerialNumber
    $NewComputerName = "whateverfrontpartyouwant" + $SN
    Rename-Computer -NewName $NewComputerName -Force -Restart

    This purges the local certs for 802.1x , Gets the Serial number from bios Creates a variable with a preset front part and serial number Renames the computer and forces a restart

    we use the above as an inventory Tool with remote run. You could modify to change the host name based off the old by calling host name or doing

    $hostname = hostname
    // returns something like Funhouse3
    $hostname.replace ("Funhouse", "NoFun")
    // returns NoFun3


    $hostname = hostname
    Rename-Computer -NewName $hostname.replace ("Funhouse", "NoFun") -Force -Restart

    You could probably use the built in PDQ variables to modify this to run local but we had the best success running it as remote.

  • Thanks sean, that looks quite nice but still missed the basic pop-up window that allow the "whateverfrontpartwewant" to be keyed then inserted into new name using powershell. the front part for us is usually a 3 letter abbreviation that changes.

  • I did some digging. best way I could find to create the popup and return it as a value is below. Running this local now instead of remote.

    $NewHname = [Microsoft.VisualBasic.Interaction]::InputBox("Enter New Hostname", "Get New Name Box", '$(Computer:TARGET)')
    Rename-Computer -computername '$(Computer:TARGET)' -NewName $NewHname -force -restart

    my reference for this

    Edit revised and cleaned up some Worked on my end up to getting access denied on rename, I think I remember this being some quirk that I didn't want to research. This is why I ran our other script local. Perhaps I'm missing something but your box popup is in this one. It references the computer name from PDQs variable, to test just the popup in PS without PDQ first run. I'm sure you can edit it to get what you need out of it.

    $CurHname = "test"
    $Value = [Microsoft.VisualBasic.Interaction]::InputBox("Enter New Hostname", "Get New Name Box", $CurHname)
  • champion, never played with powershell windows so didnt occur to me. this worked perfectly. đŸ˜„

  • Cant make variables work??

    $oldComputerName = $(COMPUTER:TARGET)

    PC-1234 : Ther term 'PC-1234' is not recognised as the name of a cmdlet, function, script file or operable program. How does one pass the PDQ variable into powershell as it doesnt work.

    also when i use the command:

    $cred = Get-credential

    no windows pops up for credentials to be entered. I'm trying to do this as need to run the Rename-Computer with credentials and the Tool doesnt pass them to powershell.

  • $oldComputerName = '$(COMPUTER:TARGET)' pass it with ' '
    For the pop up box you may need to select close shell on completion (or leave it open) in the tool editor under Shell

    If you use the tool window I think it suppresses input like that.

  • champion

  • The issue i'm having with this is that in order to get the popup to work the command needs to be run local. but then because its local the pop-up works and the script gives me a Sucess Code: 0.. But nothing happens on the remote machine. In this case i can run it as the PDQ service account or a Domain\Admin with the same result.

    $oldHostName = '$(Computer:TARGET)'
    $newHostName = [Microsoft.VisualBasic.Interaction]::InputBox("What's the computers new name?", "ComputerName", $oldHostName)
    Rename-Computer -ComputerName $oldHostName -NewName = $newHostName -force -restart

    If I just run the command without prompts as "Remote" all works fine, its the input above that breaks it.

    Rename-Computer -ComputerName ABC123 -NewName = XYZ123 -force -restart
  • do the credentials field lower in the tool apply to the powershell commands being executed, or is that only for scanning??

  • Recently had to rename 500 computers on my campus. I used this script in powershell to make it work. Use PDQ to make sure the powershell that is installed on your computers is Powershell 3.0 or above and then run it directly from powershell no need for pdq at this point. Place a csv file with the list of old computer names and new computers and call for it with the following script. Script will also have you authenticate with your admin credentials one time with a popup and then it will automatically repeat it for all of your hosts. If you get a wmi error you will need to change your remote administration settings on the computer who's name you are trying to change to be allowed in windows firewall. As far as the csv file goes do one column with heading OldName and one column with Heading NewName make sure to designate the path for where you want to pull your csv from so for example if you have put your file in the root of C:\ change the directory in your script to C:\ best of luck to you once I figured this out it saved me so much time.

    cd C:
    $Credential = Get-Credential $a = Import-Csv yourcsvfile.csv -Header OldName, NewName Foreach ( $Server in $a ) {Rename-Computer -ComputerName $Server.OldName -NewName $Server.NewName -DomainCredential $Credential -Force -Restart}

  • Is there possible to rename for windows 7 client domain-joined without Powershell?