将计算机(WMI Powershell)重命名为以前使用的名称
正在PowerShell&WMI中寻找一种方法,以使用以前使用的名称重命名计算机。此外,当通过Windows属性执行时,此过程也会成功将计算机(WMI Powershell)重命名为以前使用的名称,powershell,wmi,Powershell,Wmi,正在PowerShell&WMI中寻找一种方法,以使用以前使用的名称重命名计算机。此外,当通过Windows属性执行时,此过程也会成功 $computerSystem = Get-WmiObject -Class Win32_ComputerSystem #### Rename-Host #### Function Rename-Host { Param($computerSystem, $newComputerNa
$computerSystem = Get-WmiObject -Class Win32_ComputerSystem
#### Rename-Host ####
Function Rename-Host {
Param($computerSystem,
$newComputerName,
$username = $null,
$password = $null)
Write-Host "RenameHost: Attempting to change from $($computerSystem.DNSHostName) to $newComputerName"
Write-Host "RenameHost: Pinging for Host-Name $newComputerName to ensure it does not already exist."
$pingReturn = Ping-Addresses $newComputerName
if($pingReturn.Reachable -eq 'true'){
Write-StdErr "RenameComputer: Failed $newComputerName already exists on Network."
return
}
$oldComputerName = $computerSystem.DNSHostName
$renameResult = $computerSystem.Rename($newComputerName,$password,$username).ReturnValue
switch($renameResult){
0 { Write-Host "RenameHost: Successfully renamed $oldComputerName to $newComputerName" }
default { Write-StdErr "RenameHost: Failed with Error = $renameResult" }
}
}
“重命名计算机”命令不够用,有什么原因吗?我正在调查DHCP服务器是否保留主机名。DHCP应保留租约,直到达到超时时间。在进行大规模重命名或IP用尽时,我们已将租用时间降至5分钟,以确保尽快释放IP供使用。但是,即使DHCP有租约,只要新名称不是域的一部分,这也不应该阻止重命名。