sly*_*oty 2 windows powershell hyper-v virtual-machines
我很困惑,为什么根据我尝试从哪里检索信息,我有不同的信息。我有 3 个运行 Hyper-V 的 Windows 2012 服务器(G0、G1 和 G2)。以下情况是从我用来运行脚本并控制其他服务器的一台服务器中捕获的。
我想要做的是获取这 3 台机器上存在的虚拟机列表:
使用PowerGUI
和PowerShell ISE
:
PS > Get-VMHost | select name
Name
----
G0.nothing.com
G2.nothing.com
G1.nothing.com
PS > Get-VMHost | Get-VM | select name
Name
----
VM1628856-4
VM1628856-2
VM1628856-6
VM1628856-3
VM1628856-1
VM1628856-5
Run Code Online (Sandbox Code Playgroud)
使用PowerShell
:
PS > Get-VMHost | select name
Name
----
G0
PS > Get-VM
Name State CPUUsage(%) MemoryAssigned(M) Uptime Status
---- ----- ----------- ----------------- ------ ------
VM1107610-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1390728-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-10 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-2 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-3 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-4 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-5 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-6 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-7 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-8 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-9 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1833022-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
Run Code Online (Sandbox Code Playgroud)
我主要担心的是我没有来自 3 个工具的可靠信息。该Hyper-V Manager
应用程序显示与 相同的列表PowerShell
。但是如果我从其他两个工具运行我的脚本,这是我最常做的,我没有相同的可用信息,因此我无法操作相同的 VM。
我还注意到,它Virtual Machine Manager
显示了与前两个工具 PowerGUI 和 PowerShell ISE 相同的 VM 列表。
哪些信息有效?以及如何检索正确的 VM 列表?
该$env:psmodulepath
值:
PS > $env:psmodulepath
C:\Users\administrator\Documents\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\;
C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\Configuration Providers\;
C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\;
C:\Program Files (x86)\QLogic Corporation\QInstaller\Modules
Run Code Online (Sandbox Code Playgroud)
PowerShell
正在使用这个Hyper-V
模块:
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.HyperV.PowerShell\v4.0_6.3.0.0__31bf3856ad364e35\Microsoft.HyperV.PowerShell.dll
并且PowerGUI
正在使用这个:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Hyper-V\Hyper-V.psd1
如果我尝试将使用的模块加载到 onPowerShell
上,PowerGUI
我仍然会得到相同的不同结果。
我如何才能收到Hyper-V
使用PowerGUI
或下列出的正确信息PowerShell ISE
?
我敢打赌您正在使用两个不同的 Hyper-V PowerShell 模块:
NAME
Get-VMHost
SYNOPSIS
Lists Hyper-V servers registered with Active Directory.
Run Code Online (Sandbox Code Playgroud)
这是来自pshyperv.codeplex.com的 Get-VMhost cmdlet ,它列出了多个 Hyper-V 主机,在您的情况下为 3
NAME
Get-VMHost
SYNOPSIS
Gets a Hyper-V host.
Run Code Online (Sandbox Code Playgroud)
这是 Server 2012+ 上 Hyper-V 3 附带的 Get-VMhost cmdlet,它只列出有关一台特定主机的信息,它从不列出多台主机。
如果两个模块都已加载,则 ISE 似乎对这些模块选择了与 PoweShell 不同的偏好。
如果您在 2012 年有内置 cmdlet,我不会使用第三方 cmdlet,这只是令人困惑,它肯定会让您感到困惑。
你的价值是$env:psmodulepath
多少?
归档时间: |
|
查看次数: |
2975 次 |
最近记录: |