【发布时间】:2019-03-21 18:43:29
【问题描述】:
我可以使用Get-CimInstance Win32_UserAccount 列出远程计算机上的用户。获得用户后,我想重命名管理员帐户。下面是代码,但它不起作用。有关使这项工作的任何提示?
$hostname = "SERVER1"
$newname = "Server_Admin"
$administrator = Get-CimInstance Win32_UserAccount -ComputerName $hostname |
where SID -like 'S-1-5-*-500' -ErrorAction SilentlyContinue
$oldname = $administrator.Name
$oldname.Rename($newname)
上述命令因错误而失败
方法调用失败,因为 [System.String] 不包含名为“rename”的方法。
使用Set-CimInstance
Set-CimInstance -InputObject $administrator -Property @{name=$newname} -PassThru
报错
无法修改对象“Win32_UserAccount”的只读属性“名称”
使用的 PowerShell 版本是 5.1。
【问题讨论】:
标签: powershell