【问题标题】:Need to determine the Network Access Type of an Ethernet adapter需要确定以太网适配器的网络访问类型
【发布时间】:2019-07-11 12:17:00
【问题描述】:

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

简而言之,我试图为

找到一个类比
   (Get-NetConnectionProfile).IPv4Connectivity

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

【问题讨论】:

  • 所有可能面临类似问题或有相同要求的人。我已将代码添加到上述问题中。

标签: windows powershell wmi windows-server-2008-r2


【解决方案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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 2015-08-15
    • 1970-01-01
    相关资源
    最近更新 更多