Guest User

Untitled

a guest
Jul 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. $ComputerNames = Get-Content "P:\Tools\PowerShell\TestInput.txt"
  2. $AddressReport = @()
  3.  
  4. ForEach ($ComputerName in $ComputerNames) {
  5.  
  6. Try {
  7.  
  8. $TempReport = New-Object PSObject
  9. $IP = ((Test-Connection -ea stop -Count 1 -comp $ComputerName).IPV4Address).IPAddresstoString
  10. $TempReport | Add-Member NoteProperty Computer $ComputerName
  11. $TempReport | Add-Member NoteProperty Status "Online"
  12. $TempReport | Add-Member NoteProperty IP $IP
  13.  
  14. Try {
  15.  
  16. $ActiveUser = (Get-WmiObject –ComputerName $ComputerName –Class Win32_ComputerSystem).UserName
  17. $TempReport | Add-Member NoteProperty User $ActiveUser
  18.  
  19. }
  20.  
  21. Catch {
  22.  
  23. $TempReport | Add-Member NoteProperty User "None"
  24.  
  25. }
  26.  
  27. $AddressReport += $TempReport
  28.  
  29. }
  30.  
  31. Catch {
  32.  
  33. $TempReport = New-Object PSObject
  34. $TempReport | Add-Member NoteProperty Computer $ComputerName
  35. $TempReport | Add-Member NoteProperty Status "Down"
  36. $TempReport | Add-Member NoteProperty IP Unavailable
  37. $TempReport | Add-Member NoteProperty User Unavailable
  38. $AddressReport += $TempReport
  39.  
  40. }
  41.  
  42. }
  43.  
  44. $TimeStamp = (Get-Date -Format yyyy-mm-dd-hhmm)
  45. $ReportName = ("PingResults-" + $TimeStamp + ".csv")
  46. $AddressReport | Export-Csv -NoTypeInformation "P:\Tools\PowerShell\ExportDirectory\$ReportName"
Add Comment
Please, Sign In to add comment