Examples/AnyRepo/Repo/PreProd/OS/Get-Processes.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
param(
      [string]$ComputerName
)

[hashtable]$computer_name = @{}

if ($ComputerName) {
      $computer_name.Add('ComputerName', $ComputerName)
}

Get-WmiObject @computer_name -ClassName Win32_Process -Property Handle,ProcessID,Name,CreationDate,CommandLine,ExecutablePath -ea Stop | # foreach {
      select @{Name='ProcessID';Expression={$_.ProcessID -as [string]}}, Name, `
            @{Name='Duration (m)';Expression={'{0:N1}' -f ([datetime]::Now.Subtract($_.ConvertToDateTime($_.CreationDate))).TotalMinutes}}, `
            @{Name='UserName';Expression={try {$_.GetOwner().User} catch {}}}, `
            CommandLine