Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. Gathers various pieces of information about a system either local or remote.
  4.  
  5. .DESCRIPTION
  6. Exports all of the info to various CSV files on the local system.
  7.  
  8. .EXAMPLE
  9.  
  10. .\gatherinfo.ps1 -ComputerName DC1 -RunningProcesses -ComputerInfo
  11.  
  12.  
  13. .PARAMETER [-ComputerName]
  14. Array of systems to run the script against.
  15.  
  16. .PARAMETER [-RunningProcesses]
  17. Fetches the current running processes
  18.  
  19. .PARAMETER [-ComputerInfo]
  20. Fetches various computer info
  21. .PARAMETER [-Services]
  22. Fetches current running services
  23.  
  24. .PARAMETER [-Updates]
  25. Fetches currently installed updates
  26.  
  27. .PARAMETER [-LocalUsers]
  28. Fetches local users on the system
  29.  
  30. .PARAMETER [-DomainUsers]
  31. Fetches domain users
  32. #>
  33.  
  34. param (
  35. [string[]] $ComputerName = $env:COMPUTERNAME,
  36. [switch]$RunningProcesses,
  37. [switch]$ComputerInfo,
  38. [switch]$Services,
  39. [switch]$Updates,
  40. [switch]$LocalUsers,
  41. [switch]$DomainUsers
  42.  
  43. )
  44.  
  45.  
  46. if ($RunningProcesses.IsPresent) {Get-Process -ComputerName $ComputerName | Export-CSV -Path "1_$($ComputerName)RunningProcesses.csv"}
  47. if ($ComputerInfo.IsPresent) {
  48.  
  49. Invoke-Command -ComputerName $ComputerName -ScriptBlock
  50. {
  51. $Domain = (Get-WmiObject Win32_ComputerSsytem).Domain
  52. $CPUMan = (Get-WmiObject Win32_Processor).Manufacturer
  53. $SystemMan = (Get-WmiObject -Class win32_computersystem).Manufacturer
  54. $Version = (Get-WmiObject -Class win32_operatingsystem).version
  55. $Memory = (Get-WmiObject -Class win32_computersystem).TotalPhysicalMemory
  56. $Speed = (Get-WmiObject -Class win32_processor).MaxClockSpeed
  57. $Model = (Get-WmiObject -Class Win32_ComputerSystem).Model
  58. $Name = (Get-WmiObject -Class Win32_ComputerSystem).Name
  59.  
  60.  
  61. $info = New-Object psobject
  62. $info | Add-Member -MemberType NoteProperty -name Domain -Value $Domain
  63. $info | Add-Member -MemberType NoteProperty -name CPUManufacturer $CPUMan
  64. $info | Add-Member -MemberType NoteProperty -name SystemManufacturer $SystemMan
  65. $info | Add-Member -MemberType NoteProperty -name Version $Version
  66. $info | Add-Member -MemberType NoteProperty -name Memory $SystemMan
  67. $info | Add-Member -MemberType NoteProperty -name MaxClockSpeed $Speed
  68. $info | Add-Member -MemberType NoteProperty -name Model $Model
  69. $info | Add-Member -MemberType NoteProperty -name ComputerName $Name
  70.  
  71. $info | Export-CSV -Path "2_$($ComputerName)ComputerInfo.csv"
  72.  
  73. }
  74.  
  75. }
  76. if ($Services.IsPresent) {Get-Process -ComputerName $ComputerName | Export-CSV -Path "3_$($ComputerName)RunningServices.csv"}
  77. if ($Updates.IsPresent) {Get-Hotfix -ComputerName $ComputerName | Export-CSV -Path "4_$($ComputerName)Updates.csv"}
  78. if ($LocalUsers.IsPresent) {Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount=$True" | Export-CSV -Path "5_$($ComputerName)LocalUsers.csv"}
  79. if ($DomainUsers.IsPresent) {Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount=$False" | Export-CSV -Path "6_$($ComputerName)DomainUsers.csv"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement