Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory=$False)]
- [array]$ComputerName,
- [Parameter(Mandatory=$False)]
- [switch]$RunningProcesses,
- [Parameter(Mandatory=$False)]
- [switch]$ComputerInfo,
- [Parameter(Mandatory=$False)]
- [switch]$Updates,
- [Parameter(Mandatory=$False)]
- [switch]$LocalUsers,
- [Parameter(Mandatory=$False)]
- [switch]$DomainUsers,
- [Parameter(Mandatory=$False)]
- [switch]$Services
- )
- function getRunningProcesses {
- if ($ComputerName) {
- $procs = Get-Process -ComputerName $ComputerName -Credential CSC443\DSU
- } else {
- $procs = Get-Process
- }
- $procs | Export-Csv -Path "running-processes.csv" -Delimiter ","
- }
- function getComputerInfo {
- if ($ComputerName) {
- $os = Get-WmiObject -ComputerName $ComputerName -Class Win32_OperatingSystem -Credential CSC443\DSU
- $proc = Get-WmiObject -ComputerName $ComputerName -Class Win32_Processor -Credential CSC443\DSU
- $mem = Get-WmiObject -ComputerName $ComputerName -Class Win32_PhysicalMemory -Credential CSC443\DSU
- } else {
- $os = Get-WmiObject -Class Win32_OperatingSystem
- $proc = Get-WmiObject -Class Win32_Processor
- $mem = Get-WmiObject -Class Win32_PhysicalMemory
- }
- $os | Export-Csv -Path "os.csv" -Delimiter ","
- $proc | Export-Csv -Path "processor.csv" -Delimiter ","
- $mem | Export-Csv -Path "memory.csv" -Delimiter ","
- }
- function getUpdates {
- # could use Invoke-Expression "wmic qfe list" for wmi
- if ($ComputerName) {
- $upds = Get-Hotfix -ComputerName $ComputerName -Credential CSC443\DSU
- } else {
- $upds = Get-HotFix
- }
- $upds | Export-Csv -Path "updates.csv" -Delimiter ","
- }
- function getLocalUsers {
- if ($ComputerName) {
- $users = Get-ADUser -Filter * -SearchBase "DC=csc443,DC=lan" -ComputerName $ComputerName -Credential CSC443\DSU
- } else {
- $users = Get-ADUser -Filter * -SearchBase "DC=csc443,DC=lan"
- }
- $users | Export-Csv -Path "local-users.csv" -Delimiter ","
- }
- function getDomainUsers {
- if ($ComputerName) {
- $users = Get-ADUser -Filter * -SearchBase "DC=DomainDnsZones,DC=csc443,DC=lan" -ComputerName $ComputerName -Credential CSC443\DSU
- } else {
- $users = Get-ADUser -Filter * -SearchBase "DC=DomainDnsZones,DC=csc443,DC=lan"
- }
- $users | Export-Csv -Path "domain-users.csv" -Delimiter ","
- }
- function getServices {
- if ($ComputerName) {
- $svcs = Get-Service -ComputerName $ComputerName | Where-Object {$_.Status -eq "Running"} -Credential CSC443\DSU
- } else {
- $svcs = Get-Service | Where-Object {$_.Status -eq "Running"}
- }
- $svcs | Export-Csv -Path "services.csv" -Delimiter ","
- }
- #Import-Module ActiveDirectory
- function run {
- if ($ComputerName) {
- Write-Output "Gathering Information for: $($ComputerName -join ", ")"
- }
- if ($RunningProcesses) { getRunningProcesses }
- if ($ComputerInfo) { getComputerInfo }
- if ($Updates) { getUpdates }
- if ($LocalUsers) { getLocalUsers }
- if ($DomainUsers) { getDomainUsers }
- if ($Services) { getServices }
- Write-Output "Done!"
- }
- run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement