Script to rename and reboot a Computer throws out an file access error despite being run in an admin PowerShell

40 views Asked by At

Running a workflow which renames and restarts the computer results in an error.

I had to put in screenshots because I somehow could post the code in here.

PowerShell code

Error code

1

There are 1 answers

0
Minkulai On

is this what you're looking for?

$newName = "New name"
$computer = $env:COMPUTERNAME

Rename-Computer -ComputerName $computer -NewName $newName -Restart

Write-Host "Computer name changed to $newName. Rebooting now."

I mean, this isn't a modified version of your code but it does what it seems to be what you asked for:

Rename and reboot the computer

Please let me know if it's what you're after.