Network Information

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #28928
    Profile photo of Helder Guzman
    Helder Guzman

    Creating an HTML Report for combining two win32 classes.

    info needed:

    IP, Subnet Mask, Gateway, DNS Servers, Wins Server, sufixes, Connection, Speed, is IPV6 Enable.

    This is what i got

    $servername = "" #Read-host "`nServer DNS Name ie."
    $cred = Get-Credential -Message "User Info for Domain Server is in" -UserName "wf\u413628-a"

    $network = Get-WmiObject Win32_NetworkAdapter -ComputerName $servername -Credential $cred

    $NetworkAdapter = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $servername -Credential $cred -Filter "IpEnabled = 'True' " |
    Where-Object IPAddress -ne $null

    foreach($adapter in $NetworkAdapter){

    $props = [ordered]@{ 'IP Address' = [string]$adapter.IPAddress;
    'Subnet' = [string]$adapter.IPSubnet;
    'Gateway' = [string]$adapter.IPSubnet;
    'DNS Servers' = [string]$adapter.DNSServerSearchOrder ;
    'WINS Servers' = [string]$adapter.WINSPrimaryServer + "," + [string]$adapter.WINSsecondaryServer;
    'DNS Suffixes' = [string]$adapter.DNSDomainSuffixSearchOrder ;
    'Network Connection' = $network.NetConnectionID


    $obj = New-Object -TypeName PSObject -Property $props

    write-output $obj


    $obj |ConvertTo-Html -Fragment -as List |Out-File C:\Scripts\dns.html

    how can i add win32_networkadapter part. Inside the foreach loop? or outside.

    should I start from networkadapter first and then find the ipadress.

    combine this two classes into an object.

    Profile photo of Don Jones
    Don Jones

    First, the object has to be created and output inside the ForEach loop. Otherwise you'll only get the most recent network adapter.

    *Anything* you want on the object is going to have to be added inside the ForEach loop, before the object is output.

    And that's one script (or function). You'd then run that script (or function), and pipe its output to ConvertTo-HTML. Piping $obj to ConvertTo-HTML is only giving you the last object created, regardless of what you output to the pipeline.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.