我想在Windows 7 Sp1中使用PowerShell 2.0重命名计算机,但是出现错误。
PS C:\Windows\system32> Rename-Computer -NewName PC02
The term 'Rename-Computer' is not recognized as the name of a cmdlet, function, script f
ile, or operable program. Check the spelling of the name, or if a path was included, ver
ify that the path is correct and try again.
At line:1 char:16
+ Rename-Computer <<<< -NewName PC02
+ CategoryInfo : ObjectNotFound: (Rename-Computer:String) [], CommandNotFo
undException
+ FullyQualifiedErrorId : CommandNotFoundException
答案 0 :(得分:5)
那是因为Rename-Computer
是在Powershell 3.0中引入的
答案 1 :(得分:2)
要在PowerShell 2.0中执行此操作,请使用WMI:
(Get-WmiObject Win32_ComputerSystem).Rename('PC02')
您可以在 Get-WmiObject 之后添加-ComputerName CURRENTNAME
来重命名远程计算机。
您必须从提升的提示中执行此操作。当然,这需要重启才能生效。