Creating A Table based on the outputs/results

Answered Creating A Table based on the outputs/results

  • Friday, September 14, 2012 2:23 PM
     
      Has Code
    $colItems = Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" | where {$_.Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox'}
    
    ForEach ($objItem in $colItems) {
            $objItem.MacAddress
    		$objItem.Name
    		$objItem.PSComputerName
    		
        } 

    How do i create a a table with the following headings

    Pscomputername
    Name
    MacAddress

    Also i would like to export the information as a txt or csv file. 

    thanks

    -metho


All Replies

  • Friday, September 14, 2012 2:28 PM
     
     Answered Has Code

    Easy peasy

    $colItems = Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" |

    where {$_.Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox'} &{ForEach ($objItem in $colItems) { $objItem | select PSComputerName,Name,MacAddress } } | Export-Csv c:\somedir\mycsv.csv -NoTypeInformation



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


  • Friday, September 14, 2012 2:29 PM
     
     Answered Has Code

    PowerShell V3:

    Table:

    Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" | where Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox' | ft Pscomputername,Name,MacAddress -Auto

    Export:

    Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" | where Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox' | select Pscomputername,Name,MacAddress | export-csv -Notype result.csv

    PowerShell V2:

    Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" | where {$_.Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox'} | ft @{n="Pscomputername";e={$_.__Server}},Name,MacAddress -Auto

    • Marked As Answer by iM3th0 Saturday, September 15, 2012 7:35 AM
    •  
  • Friday, September 14, 2012 2:31 PM
     
     Answered Has Code
    $colItems = Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" | where {$_.Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox'}
    $results = New-Object System.Collections.ArrayList
    ForEach ($objItem in $colItems) {
            $props = @{'MACAddress' = $objItem.MacAddress
    		           'Name' = $objItem.Name
    		           'CompName' = $objItem.PSComputerName }
            $results += New-Object PSObject -Property $props
    		} 
    $results | Export-Csv -Path 'Results.csv' -NoTypeInformation


    Grant Ward, a.k.a. Bigteddy

    • Marked As Answer by iM3th0 Saturday, September 15, 2012 7:35 AM
    •  
  • Tuesday, September 18, 2012 2:09 PM
     
      Has Code

    thanks very much for the earlier responds, now just to make things more interseting, i have a criteria where i need to run the script remotly to obtain the information (MacAddress, Name, Computername) from a set of remote computers.

    $machines = Get-Content “C:\Users\metho\Desktop\newname.txt”
    [ScriptBlock] $script = {
    
    $colItems = Get-WmiObject Win32_NetworkAdapter -Filter "PhysicalAdapter='True'" | where {$_.Name -match 'Wireless|Bluetooth|Wifi|Intel|VirtualBox'}
    $results = New-Object System.Collections.ArrayList
    ForEach ($objItem in $colItems) {
            $props = @{'MACAddress' = $objItem.MacAddress
    		           'Name' = $objItem.Name
    		           'CompName' = $objItem.PSComputerName }
            $results += New-Object PSObject -Property $props
    		} 
    $results | Export-Csv -Path 'c:\Results.csv' -NoTypeInformation
    
    }
    
    $cred = Get-Credential
    $sessions = $machines | New-PSSession -Credential $cred
    Invoke-Command -ScriptBlock $script -Session $sessions
    $sessions | Remove-PSSession
    this script runs fine on remote computers but it fails to achieve what i exectly want, first it creates a file (c:\Results.csv) and dumps on the remote computer and also it doesnt produce the PSComputername (of the remote computers), basically how do i get the output of remote hosts back on my local computer stored in csv formet with the information i needed. 

     
  • Tuesday, September 18, 2012 2:13 PM
     
     Answered
    Why not just add the -computername parameter to Get-WMIObject?

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


  • Tuesday, September 18, 2012 2:58 PM
     
     
    Why not just add the -computername parameter to Get-WMIObject?

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


    thanks, it worked (till next time, lol)