Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. [CmdletBinding()]
  2. Param(
  3. [Parameter(Mandatory=$False)]
  4. [array]$ComputerName,
  5. [Parameter(Mandatory=$False)]
  6. [switch]$RunningProcesses,
  7. [Parameter(Mandatory=$False)]
  8. [switch]$ComputerInfo,
  9. [Parameter(Mandatory=$False)]
  10. [switch]$Updates,
  11. [Parameter(Mandatory=$False)]
  12. [switch]$LocalUsers,
  13. [Parameter(Mandatory=$False)]
  14. [switch]$DomainUsers,
  15. [Parameter(Mandatory=$False)]
  16. [switch]$Services
  17. )
  18.  
  19. function getRunningProcesses {
  20. if ($ComputerName) {
  21. $procs = Get-Process -ComputerName $ComputerName -Credential CSC443\DSU
  22. } else {
  23. $procs = Get-Process
  24. }
  25.  
  26. $procs | Export-Csv -Path "running-processes.csv" -Delimiter ","
  27. }
  28.  
  29. function getComputerInfo {
  30. if ($ComputerName) {
  31. $os = Get-WmiObject -ComputerName $ComputerName -Class Win32_OperatingSystem -Credential CSC443\DSU
  32. $proc = Get-WmiObject -ComputerName $ComputerName -Class Win32_Processor -Credential CSC443\DSU
  33. $mem = Get-WmiObject -ComputerName $ComputerName -Class Win32_PhysicalMemory -Credential CSC443\DSU
  34. } else {
  35. $os = Get-WmiObject -Class Win32_OperatingSystem
  36. $proc = Get-WmiObject -Class Win32_Processor
  37. $mem = Get-WmiObject -Class Win32_PhysicalMemory
  38. }
  39. $os | Export-Csv -Path "os.csv" -Delimiter ","
  40. $proc | Export-Csv -Path "processor.csv" -Delimiter ","
  41. $mem | Export-Csv -Path "memory.csv" -Delimiter ","
  42. }
  43.  
  44. function getUpdates {
  45. # could use Invoke-Expression "wmic qfe list" for wmi
  46. if ($ComputerName) {
  47. $upds = Get-Hotfix -ComputerName $ComputerName -Credential CSC443\DSU
  48. } else {
  49. $upds = Get-HotFix
  50. }
  51. $upds | Export-Csv -Path "updates.csv" -Delimiter ","
  52. }
  53.  
  54. function getLocalUsers {
  55. if ($ComputerName) {
  56. $users = Get-ADUser -Filter * -SearchBase "DC=csc443,DC=lan" -ComputerName $ComputerName -Credential CSC443\DSU
  57. } else {
  58. $users = Get-ADUser -Filter * -SearchBase "DC=csc443,DC=lan"
  59. }
  60. $users | Export-Csv -Path "local-users.csv" -Delimiter ","
  61. }
  62.  
  63. function getDomainUsers {
  64. if ($ComputerName) {
  65. $users = Get-ADUser -Filter * -SearchBase "DC=DomainDnsZones,DC=csc443,DC=lan" -ComputerName $ComputerName -Credential CSC443\DSU
  66. } else {
  67. $users = Get-ADUser -Filter * -SearchBase "DC=DomainDnsZones,DC=csc443,DC=lan"
  68. }
  69. $users | Export-Csv -Path "domain-users.csv" -Delimiter ","
  70. }
  71.  
  72. function getServices {
  73. if ($ComputerName) {
  74. $svcs = Get-Service -ComputerName $ComputerName | Where-Object {$_.Status -eq "Running"} -Credential CSC443\DSU
  75. } else {
  76. $svcs = Get-Service | Where-Object {$_.Status -eq "Running"}
  77. }
  78. $svcs | Export-Csv -Path "services.csv" -Delimiter ","
  79. }
  80.  
  81. #Import-Module ActiveDirectory
  82.  
  83. function run {
  84. if ($ComputerName) {
  85. Write-Output "Gathering Information for: $($ComputerName -join ", ")"
  86. }
  87.  
  88. if ($RunningProcesses) { getRunningProcesses }
  89. if ($ComputerInfo) { getComputerInfo }
  90. if ($Updates) { getUpdates }
  91. if ($LocalUsers) { getLocalUsers }
  92. if ($DomainUsers) { getDomainUsers }
  93. if ($Services) { getServices }
  94.  
  95. Write-Output "Done!"
  96. }
  97.  
  98. run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement