需要确定以太网适配器的网络访问类型

问题描述 投票:2回答:1

我需要尝试找出各种虚拟机上的以太网连接的网络访问类型。

总之,我试图找到一个类比

    Get-NetConnectionProfile).IPv4Connectivity

从Windows 2012开始运行良好,我希望针对Windows 2008 R2服务器运行此查询。

windows powershell wmi windows-server-2008-r2
1个回答
1
投票

我在Windows 2008服务器上使用.NET类,在PowerShell中强制转换为对象,示例代码如下:

    $nlm = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
    $nlm.GetNetworkConnections() | ForEach-Object { 
                                    [PSCustomObject]@{
                                    NetworkName = ($_.GetNetwork().GetName());
                                    isConnectedToInternet = $_.isConnectedToInternet;
                                   } 
    if ($nlm.IsConnectedToInternet)
            {
                $NLAState = 'Internet'
            }
            "Access type : $NLAState"
© www.soinside.com 2019 - 2024. All rights reserved.