Rename pc interactive powershell

Hi,
Am very new to SimpleHelp and trying to make a power shell script to rename a pc and ask the technician for the new name.

# Prompt technician for new computer name (text input)
$renamemachine = ServerUtilsAskTech(Enter new computer name:, text)

# Check if input is empty or null
if ([string]::IsNullOrWhiteSpace($renamemachine)) {
    Write-Output "No name entered. Aborting."
    exit
}

# Rename the computer
Rename-Computer -NewName "$renamemachine" -Force

Keep getting no name entered. Aborting… then, testbord11 is not recognized as the name of a cmdlet, function, script file etc…

I don’ t think the variable is being set?

I ran into this same problem when first starting out. You just need to change where you’re using quotes.

try using quotes around the function call when assigning to a variable:
$renamemachine = “ServerUtilsAskTech(Enter new computer name:, text)”

drop the quotes around your variable when renaming:
Rename-Computer -NewName $renamemachine -Force

Good luck!

How about that! It worked!! Thank You
Here’s the finished code.

# Prompt technician for new computer name (text input)
$renamemachine = "ServerUtilsAskTech(Enter new computer name:, text)"

# Check if input is empty or null
if ([string]::IsNullOrWhiteSpace($renamemachine)) {
    Write-Output "No name entered. Aborting."
    exit
}

# Rename the computer
Rename-Computer -NewName $renamemachine -Force

Run as powershell script
Set Wait for the tool to complete before returning
Choose Run as the service user

1 Like