能否通过powershell给hyper-v虚拟机内的系统注入计算机名?


PowerShell交流中心分类: Powershell基础能否通过powershell给hyper-v虚拟机内的系统注入计算机名?
0
喊珐刽谩留争 asked 6 年 ago

能否通过powershell给hyper-v虚拟机内的系统注入计算机名?不是虚拟机名。

hunter_huang replied 6 年 ago

1. Enable PowerShell remoting session in your VM, Enable-PSRemoting -SkipNetworkProfileCheck -Force -Verbose
2. From your host machine, create the PS session to your VM, $Session = New-PSSession -VMName TestVM-001 -Verbose -Credential xxx\username
3. rename the vm computer name, Invoke-Command -Session $Session -ScriptBlock {Rename-Computer -NewName VMMachine001 -Restart}

1 Answers
2
Best Answer
zbluesky answered 6 年 ago
  1. 如果宿主机网络可以连通虚拟机,那么使用远程管理连接虚拟机的PowerShell session,然后改名。或者直接调用Rename-Computer 连接远程计算机改名。
  2. 如果使用Windows 10或者Windows Server 2016的Hyper-V,可以使用 PowerShell Direct 连接到虚拟机中,然后改名。参考:
    https://docs.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/user-guide/powershell-direct 
    使用 PowerShell 实现虚拟机自动化和管理虚拟机