This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
howdy y'all,
i've been playing off-n-on with a SysInfo script. it does NOT cover everything, but i think i have what is needed.
so, i have questions ...
[this is all being done on my win7x64, ps5.1 box - and also used on several win7 CAD systems. the printer, dns, and most net cmdlets are all win8.1 or win10.]
[0] does it work on your system?
[1] did i leave out anything that you consider important?
[2] how do i get the ipv6 DNS servers?
i can see it with ipconfig /all
but it don't show up with CIM/WMI as far as i can tell.
[3] converting the DNS servers [ipaddress]
object array to a string
the way i originally had that set up, it gave the two addresses in {}
. that bothered me - an array in a property list where i know the guys who are currently using this code will expect only flat objects.
so converted it to 208.67.222.222; 208.67.220.220
and left it that way.
is there any real use in leaving it an array instead of a string?
[4] unable to find CIM/WMI ipv6 DefaultGateway & DHCP_Server info
are there ipv6 DefaultGateway & DHCP_Server items buried somewhere?
here's the code ...
$SysInfoProps = [ordered]@{}
Write-Information ' getting CIM_NetworkAdapter & Win32_NetworkAdapterConfiguration info ...'
# this is a regex OR, so put a '|' between each item you want to exclude
#$ExcludedNetAdapterList = 'Npcap|VirtualBox'
$ExcludedNetAdapterList = 'Npcap'
$CIM_NetAdapter = Get-CimInstance -ClassName CIM_NetworkAdapter
$CIM_NetConfig = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration |
Where-Object {
$_.IPEnabled -and
$_.Description -notmatch $ExcludedNetAdapterList
}
foreach ($CNC_Item in $CIM_NetConfig)
{
$Index = '{0:D2}' -f $CNC_Item.Index
$SysInfoProps.Add("Net_${Index}_AdapterIndex", $CNC_Item.Index)
$SysInfoProps.Add("Net_${Index}_AdapterName", $CNC_Item.Description)
$SysInfoProps.Add("Net_${Index}_AdapterManufacturer", $CIM_NetAdapter[$Index].Manufacturer)
# using 1e9 instead of 1GB since the NIST uses base 10
$SysInfoProps.Add("Net_${Index}_AdapterSpeed_Gbit", $CIM_NetAdapter[$Index].Speed / 1e9)
$DefaultGateway = if ($CNC_Item.DefaultIPGateway -is [array])
{
$CNC_Item.DefaultIPGateway[0]
}
else
{
$Null
}
$SysInfoProps.Add("Net_${Index}_DefaultGateway", $DefaultGateway)
$SysInfoProps.Add("Net_${Index}_DHCP_Enabled", $CNC_Item.DHCPEnabled)
$SysInfoProps.Add("Net_${Index}_DHCP_Server", $CNC_Item.DHCPServer)
$SysInfoProps.Add("Net_${Index}_DNS_HostName", $CNC_Item.DNSHostName)
# on my system the addresses are stored [0]=IPv4, [1]=IPv6
# the [ipaddress] conversion fails with ipv6 subnet info
# "64" becomes "0.0.0.64" [ipv4] instead of "64" or "::64" [ipv6]
$SysInfoProps.Add("Net_${Index}_IPv4_Address",
([ipaddress[]]$CNC_Item.IPAddress).
Where({$_.AddressFamily -eq 'Internetwork'}) -join '; ')
$SysInfoProps.Add("Net_${Index}_IPv4_AddressSubnet", $CNC_Item.IPSubnet[0])
$SysInfoProps.Add("Net_${Index}_IPv4_DNS_Servers",
([ipaddress[]]$CNC_Item.DNSServerSearchOrder).
Where({$_.AddressFamily -eq 'Internetwork'}) -join '; ')
$SysInfoProps.Add("Net_${Index}_IPv6_Address",
([ipaddress[]]$CNC_Item.IPAddress).
Where({$_.AddressFamily -eq 'InternetworkV6'}) -join '; ')
$SysInfoProps.Add("Net_${Index}_IPv6_AddressSubnet", $CNC_Item.IPSubnet[1])
# IPV6 DNS servers are shown in "ipconfig /all", but not with CIM
# so this will be blank on my system
$SysInfoProps.Add("Net_${Index}_IPv6_DNS_Servers",
([ipaddress[]]$CNC_Item.DNSServerSearchOrder).
Where({$_.AddressFamily -eq 'InternetworkV6'}) -join '; ')
$SysInfoProps.Add("Net_${Index}_MAC_Address", $CNC_Item.MACAddress)
}
$SysInfoProps
take care,
lee
Subreddit
Post Details
- Posted
- 6 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PowerShell/...