Win32_useraccount CIMInstance Rename User

$hostname = "ASH-FILERAV3"
$newname = "Server_Admin"
#$administrator = get-wmiobject -Class win32_useraccount -Filter "domain='$hostname'" | where name -like "Administrator"
$administrator = get-ciminstance win32_useraccount -ComputerName $hostname  | where SID -Like 'S-1-5-*-500' -ErrorAction SilentlyContinue
$oldname = $administrator.Name
#set-ciminstance -InputObject $administrator -Property @{name=$newname} -PassThru
get-ciminstance win32_useraccount -ComputerName $hostname | where SID -Like 'S-1-5-*-500' | select Name,FullName,Status,Disabled,Lockout,Domain,LocalAccount,SID,SIDType,AccountType | sort Status | format-table -groupby Status -Property Name,FullName,Status,Disabled,Lockout,Domain,LocalAccount,SID,SIDType,AccountType

The idea behind this script is to rename the administrator account on multiple servers remotely. I am not able to rename the user. Unable to find any reference or examples on how to do this. Trying not use WMIC and/or ADSI.

PowerShell version I am using is 5.1.17763.316<!–more–><!–more–>

Is there a special reason why you’re not using the built in cmdlet Rename-LocalUser?

And please format your code as code using the code tag button (pre) of the post editor.