我需要尝试找出各种虚拟机上的以太网连接的网络访问类型。
总之,我试图找到一个类比
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"