【问题标题】:CMD to determine a 'Public Network' in active networksCMD 确定活动网络中的“公共网络”
【发布时间】:2015-08-27 13:01:07
【问题描述】:

我试图弄清楚如何确定活动网络何时是公共的。有没有办法通过 WMIC 或 CMD 提示来实际显示“公共”作为状态? netstat 似乎没有给我我想要的东西,IPconfig 没有显示“公共”。我在 Powershell 中尝试了 Get-NetConnectionProfile,但没有运气:(

“Get-NetConnectionProfile”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,如果包含路径,请验证路径是否正确,然后重试。

在 line:1 char:25

  • 获取网络连接配置文件
  • CategoryInfo : ObjectNotFound: (Get-NetConnectionProfile:String) [], CommandNotFoundException
  • FullyQualifiedErrorId:CommandNotFoundException

有什么想法吗?

【问题讨论】:

  • 我在 Powershell 中尝试了 Get-NetConnectionProfile,但没有成功:(您遇到了什么具体问题?
  • Get-NetConnectionProfile :术语“Get-NetConnectionProfile”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 line:1 char:1 + Get-NetConnectionProfile + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-NetConnectionProfile:String) [] , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
  • 操作系统? PowerShell 版本?
  • Win 7 64,Powershell ISE v1.0

标签: cmd


【解决方案1】:

我为你找到了答案!

这使用 PowerShell 和 WMI 来获得您的答案。我已经在具有域和公共互联网设置的机器上进行了测试(没有任何专用网络,抱歉)

     Get-WmiObject MSFT_NetConnectionProfile -Namespace root/StandardCimv2 | 
       select Name,@{n='ActiveNetworkProfile';e={
         switch ($_.NetworkCategory){
             0 {'Public'}
             1 {'Private'}
             2 {'Domain'} 
             Default {$_.NetworkCategory}
            }
          }
        }

运行它会给你以下输出:

如果您想简单地了解活动配置文件是什么,请将上述内容通过管道传输到Select -Unique ActiveNetworkProfile,这将提供以下输出。

【讨论】:

  • 如果您好奇我是如何找到答案的,我used this post 想知道如何反编译 PowerShell cmdlet。然后我反编译了 Get-NetConnectionProfile cmdlet 以查看它正在查询的 WMI 类。好玩!
  • 谢谢,但我得到 Get-WmiObject : Invalid namespace "root/StandardCimv2" At C:\Temp\powershell\commoncommands.ps1:700 char:1 + Get-WmiObject MSFT_NetConnectionProfile -Namespace root /标准Cimv2 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObj ectCommand跨度>
  • 糟糕,我刚刚注意到这个 WMI 命名空间只存在于 Windows 8 及更高版本中。简短的回答?你想要的东西在 Windows 7 中是非常非常难以获得的,如果它甚至可以找到的话。
  • 感谢您的尝试。
猜你喜欢
  • 1970-01-01
  • 2017-02-08
  • 1970-01-01
  • 2013-02-06
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-24
相关资源
最近更新 更多