Powershell Script to ping and report on computers, export to CSV

2 April 2020:Microsoft is "retiring" the Technet Gallery effective June 2020 - see https://docs.microsoft.com/en-us/teamblog/technet-gallery-retirementTo continue to provide updates to this script, its functionality has been ported out to the Get-PCInfo function of the AZSBTools

 
 
 
 
 
3.9 Star
(25)
75,572 times
Add to favorites
4/3/2020
E-mail Twitter del.icio.us Digg Facebook
  • Access denied error
    1 Posts | Last post December 20, 2019
    • Hello, I am getting an access denied error. I am able to ping the Computer's IP address. What sort of permissions are needed to run this script. I am running the script with a csv file with the computerNames.
  • This script does not work
    1 Posts | Last post October 10, 2019
    • Hi the snipit you have vs the actual script it does not work.
  • Script with GridView - Export to CSV and Convert to XLSX
    1 Posts | Last post August 21, 2019
    • Include and change the Code for:
      
      Add-Type -AssemblyName PresentationFramework
          $msgBoxInput =  [System.Windows.MessageBox]::Show('Testar conexão e exportar relatório?','Report Ping', 'YesNo')
      
          switch  ($msgBoxInput) {
        
          'Yes' {
      
      $CSVFile = ".\Ping-Report.csv"
      $ComputerList = ".\computerlist.txt"
      $PCData = foreach ($PC in ((Get-Content -Path $ComputerList))) {
      
      __________________________________________________________________________________________
      
      Include this code at end of code:
      
      $PCData | Sort ComputerName | FT -AutoSize
      $PCData | Sort ComputerName | Out-GridView
      $PCData | Sort ComputerName | Export-Csv -Path $CSVFile -Delimiter ';' -NoTypeInformation
          select ComputerName, Status, OSVersion, OSCaption, OSArchitecture, IPAddress, MacAddress, VM, Model, Manufacturer, DateBuilt, LastBootTime
      
      
      $csv = "C:\Temp\Ping-Report.csv" #Local do Arquivo de Origem
      $xlsx = "C:\Temp\Ping-Report.xlsx" #Local do arquivo de Destino
      $delimiter = ";" # Especifica o delimitador ";" para que o arquivo XSLS separe os campos
      
      # Cria uma nova planilha em branco no excel
      $excel = New-Object -ComObject excel.application 
      $workbook = $excel.Workbooks.Add(1)
      $worksheet = $workbook.worksheets.Item(1)
      
      # Cria uma consulta na tabela com formatação de Tipos
      
      $TxtConnector = ("TEXT;" + $csv)
      $Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1"))
      $query = $worksheet.QueryTables.item($Connector.name)
      $query.TextFileOtherDelimiter = $delimiter
      $query.TextFileParseType  = 1
      $query.TextFileColumnDataTypes = ,1 * $worksheet.Cells.Columns.Count
      $query.AdjustColumnWidth = 1
      
      # Executa e deletas as consultas
      $query.Refresh()
      $query.Delete()
      
      # Salva e fecha a planilha em Excel
      $Workbook.SaveAs($xlsx,51)
      $excel.Quit()
      
      [System.Windows.MessageBox]::Show('Executado !! - Relátorio gerado na pasta do aplicativo','Report Ping')
      
      }
      
      'No' {
      
          Get-Event | Remove-Event
        
          }
        
        }
  • Not understanding how Ping-Report-v3 reads from a list
    1 Posts | Last post July 05, 2019
    • Hi Sam, I'm new to Powershell.  This script fits the bill for something I'm trying to accomplish, but I don't understand how to get the syntax to pull from a list to get the output you have structured.  How do I get this script to pull read from a list of server names?
      
      Thanks,
      
      Shawn
  • how i can configure mail function for to get the reports to windows live mail or outlook mail
    1 Posts | Last post May 16, 2019
    • how i can configure mail function for to get the reports to windows live mail or outlook mail?
      
  • PingReport Result
    2 Posts | Last post March 03, 2019
    • Two things...
      1) How do you add more workstations for the script to ping?
      2) Where is the result report saved in?
      
      Thanks in advance
    • Wrong description maybe
  • What does "Requires -Version 2" mean?
    2 Posts | Last post February 06, 2019
    • First line of the script is #Requires -Version 2. Just wondering what that means.
    • Ooohhh, requires POWERSHELL version 2, right? Not version 2 of your script. DUH
  • Additional Info
    1 Posts | Last post December 10, 2018
    • So disregard the last comment I ended up getting the script to work I just had to invoke a command to run the script (which I missed the info).
      
      So I ran:
       Import-Csv .\Computerlist.csv | 
        % { .\Ping-Report-v3.ps1 $_.ComputerName } | 
          select ComputerName, Status, OSCaption, MACAddress, IPAddress, LastBootTime |
            Export-Csv C:\_localdata\report1.csv -NoType
      
      My question now, is in the script itself, how can I get it to read the IP status i.e. Request Timed Out, Bad Hostname etc. As it stands and the way it was written only produces an IP address when pingable which is great and what I like, but if it is not pingable I need to have the report read if it was 'Request Timed Out' or 'Bad Hostname'. As it stands it says "No response to ping" or "Access Denied".
      
      I found information on the script I want to use but don't know where in this script I can add or what to modify:
      $ping = ping $Server -n 1 | Where-Object {$_ -match "Reply" -or $_ -match "Request timed out" -or $_ -match "Destination host unreachable"}
      (http://www.powershellbros.com/powershell-function-to-check-failed-ping-status-request-timed-out/)
  • Missing Info
    1 Posts | Last post December 09, 2018
    • I am unable to get this script to work for multiple computers, or to get it to export the info to a log file. When I ran the script it simply provided the date for the computer that I was on. I am hoping someone could help with the exact data I should input and where exactly to put it I a very big newbie to power shell, and scripts.
  • Email attachment missing
    1 Posts | Last post June 01, 2018
    • i get following error
      
      Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send 
      anonymous mail during MAIL FROM 
      At line:41 char:1
      + Send-MailMessage @messageParameters –BodyAsHtml
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
          + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
       
1 - 10 of 24 Items