Network Information

Welcome Forums General PowerShell Q&A Network Information

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 9 months ago.

  • Author
  • #28928

    Topics: 9
    Replies: 7
    Points: 0
    Rank: Member

    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.

  • #28930

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Network Information’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort