Windows Server 2012 R2 Powershell IP 接口隔间

Windows Server 2012 R2 Powershell IP 接口隔间

如果我运行Get-NetIPInterface -ifIndex 29 -IncludeAllCompartments,我会得到一个界面。

我通过 查过,只有 2 个隔间@(Get-NetCompartment).Count。隔间 ID 为 1 和 2。此信息也由 打印Get-NetCompartment

但是如果我运行 Get-NetIPInterface -CompartmetId 2 我会收到此错误:

PS C:\Users\Administrator> Get-NetIPInterface -ifIndex 29 -CompartmentId 1
Get-NetIPInterface : No matching MSFT_NetIPInterface objects found by CIM query for instances of the
ROOT/StandardCimv2/MSFT_NetIPInterface class on the  CIM server: SELECT * FROM MSFT_NetIPInterface  WHERE
((InterfaceIndex = 29)) AND ((CompartmentId = 1)). Verify query parameters and retry.
At line:1 char:1
+ Get-NetIPInterface -ifIndex 29 -CompartmentId 1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_NetIPInterface:String) [Get-NetIPInterface], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound,Get-NetIPInterface

或这个

PS C:\Users\Administrator> Get-NetIPInterface -ifIndex 29 -CompartmentId 2
Get-NetIPInterface : No matching MSFT_NetIPInterface objects found by CIM query for instances of the
ROOT/StandardCimv2/MSFT_NetIPInterface class on the  CIM server: SELECT * FROM MSFT_NetIPInterface  WHERE
((InterfaceIndex = 29)) AND ((CompartmentId = 2)). Verify query parameters and retry.
At line:1 char:1
+ Get-NetIPInterface -ifIndex 29 -CompartmentId 2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_NetIPInterface:String) [Get-NetIPInterface], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound,Get-NetIPInterface

PS C:\Users\Administrator>

为什么我会收到此错误?
如果接口不在隔间 1 中也不在隔间 2 中,那么它在哪里?

更多信息:

PS C:\Users\Administrator>  Get-NetIPInterface -ifIndex 29 -IncludeAllCompartments

ifIndex InterfaceAlias                  AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp     ConnectionState PolicyStore
------- --------------                  ------------- ------------ --------------- ----     --------------- -----------
29      NIC_INTERN_CONTOSO              IPv4                  1500               5 Disabled Connected       ActiveStore

PS C:\Users\Administrator> Get-NetCompartment


CompartmentId          : 1
CompartmentDescription : Default Compartment
CompartmentGuid        : !SOME NUMBERS!

CompartmentId          : 2
CompartmentDescription : COMPARTMENT2
CompartmentGuid        : !SOME NUMBERS"

答案1

您应该能够使用类似这样的方法找出它所在的 CompartmentId:

Get-NetIPInterface -ifIndex 29 -IncludeAllCompartments | ForEach-Object { "$($_.InterfaceAlias) - $($_.CompartmentId)" }

使用它来检查它是否确实在其中一个隔间中。

相关内容