windows - 需要确定以太网适配器的网络访问类型
问题描述
我需要尝试找出各种虚拟机上以太网连接的网络访问类型。
简而言之,我试图找到一个类比
(Get-NetConnectionProfile).IPv4Connectivity
从 Windows 2012 开始效果很好,我希望针对 Windows 2008 R2 服务器运行此查询。
解决方案
我在 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"
推荐阅读
- axon - 有没有办法直接从测试夹具测试事件而不使用expectEvents?
- php - php登录不会在服务器上重定向
- excel - 按下 Enter 键时如何防止光标移动到下一个文本框?
- jquery - 在 jquery ajax 中的某些内容上显示和隐藏 gif 图像
- python - 在python中生成一个不重复的随机数而不给出范围
- palantir-foundry - 如果我们需要使用 magrite 代理进行两步休息 api 调用?怎么走一样?
- haskell - 递归解决有关访问无限列表的某些元素的问题
- javascript - 悬停在其他元素下方的元素可能悬停
- vue.js - Gitlab CI / Pipelines 中忽略了 VueJS Webpack 别名
- emacs - emacs 在 gud 调试命令上保存所有缓冲区