Slime
Slime

Reputation: 3

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

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

Upvotes: 0

Views: 55

Answers (1)

Minkulai
Minkulai

Reputation: 124

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.

Upvotes: 0

Related Questions