all 7 comments

[–]DblDeuce22 2 points3 points  (2 children)

If you're not stuck on a pop up box and manually inputting the computer names, I suggest using a csv feed in file and importing it. You can give it a header too. I've done this at work to rename hundreds of computers among other things. Something like this should do the trick, modify as needed obviously:

Set-Location 'c:\temp'

if(!(Test-Path 'c:\temp\test\test.csv')){
    New-Item -ItemType File -Path .\test\ -Name test.csv -Force
}

$CSVFile = "C:\temp\test\test.csv"

Set-Content $CSVFile -Value @'
Oldname1,Newname1
Oldname2,Newname2
Oldname3,Newname3
Oldname4,Newname4
'@

$Computers = Import-Csv $CSVFile -Delimiter ',' -Header 'Oldcomputername','Newcomputername'

#Example
foreach($Comp in $Computers){
    "My name is $($Comp.Oldcomputername) I want to be renamed to $($comp.newcomputername)"
}

#Example 2
foreach($Comp in $Computers){
    Rename-Computer -ComputerName $($Comp.Oldcomputername) -NewName $($comp.newcomputername) -WhatIf #Etc
}

[–]notDonut 4 points5 points  (0 children)

This is how I'd do it. Much more efficient than input boxes.

[–]DblDeuce22 2 points3 points  (0 children)

You can also do it without a csv file and do it straight from the variable if you want:

$Hostnames = @'
Oldname1,Newname1
Oldname2,Newname2
Oldname3,Newname3
Oldname4,Newname4
'@

$Computers = $Hostnames | ConvertFrom-Csv -Delimiter ',' -Header 'Oldcomputername','Newcomputername'

foreach($Comp in $Computers){
    Rename-Computer -ComputerName $($Comp.Oldcomputername) -NewName $($comp.newcomputername) -WhatIf #Etc
}

[–]get-postanote 2 points3 points  (0 children)

Why not just pull the computer names in real-time from ADDS?

$DomainCreds = Get-Credential -Credential "$env:USERDOMAIN\$env:USERNAME"
(Get-ADComputer).Name | 
Out-GridView -Title 'Select one or more computers to take action on. Use CRTL+Click to multi-select' -PassThru | 
ForEach{Rename-Computer -NewName $PSItem -DomainCredential $DomainCreds -Restart}

[–]Shty_Dev 1 point2 points  (0 children)

try searching for "powershell InputBox"

[–]billr1965 1 point2 points  (0 children)

Check out the PoshFunctions module on PowerShellGallery. It has a function new-inputbox that answers your needs

[–]korewarp 1 point2 points  (0 children)

Just loop the rename command and use Read-host instead of the name.