Need help with combining some scripts RRS feed

  • General discussion


    I have three scripts that I run in PowerShell to get information I need from remote workstations.   I would like this to be accomplished with just one script instead of three.  What I need to get from the remote stations is Hostname, IP Address, MAC Address, Operating System, 32-bit or 64-bit, serial number or service tag number.   I need to be able to run the scripts using a list of either Host Names or IP Addresses and export to a CSV file.   Here is what I have so far.

    Get-Content C:\Users\username\Desktop\IPs.txt |
      Where-Object { Test-Connection $_ -Count 2 -Quiet } |
      ForEach-Object {
        $IPAddress = $_
        Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
        Where-Object { $_.IPAddress -contains $IPAddress } |
        Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName
      } | Export-Csv C:\Users\username\Desktop\MACAddressReport.csv -NoTypeInformation

    $computerlist = Get-Content C:\Users\username\Desktop\IPs.txt
    foreach ($computer in $computerlist) {
        if((Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
            Get-WMIObject Win32_OperatingSystem -ComputerName $computer |
            select-object CSName, Caption | export-csv -Path C:\Users\username\Desktop\MACAddressReport-2.csv -NoTypeInformation -Append

    get-content C:\Users\username\Desktop\HostNames.txt |
       select-object `
         @{n = 'IP'; e = { [Net.Dns]::GetHostEntry($_).AddressList } },
         @{n= 'Name'; e = { $_ } } |
       Export-Csv C:\Users\username\Desktop\IPAddressReport.csv -NoTypeInformation

    Any help would be greatly appreciated.

    Friday, July 14, 2017 12:36 PM

All replies