I am trying to rename Windows (10) PC using a PowerShell command in a generic script. Here is what I have so far, but it doesn't work:
Rename-Computer -NewName "New-Name-Based-On-Script-Parent-Folder" -DomainCredential [System.Security.Principal.WindowsIdentity]::GetCurrent().Name -Restart
I have tried running this in a PowerShell instance with administrator privileges, as well as an administrative instance of PowerShell ISE (after running Set-ExecutionPolicy Bypass -Scope Process
of course), but to no avail.
Ideally, I would like this to run on any Windows PC and rename it according to the name of the parent folder that the script resides in. Any suggestions on what I'm doing wrong? Thanks.