Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Get-process and Get-services in one file

$
0
0

Hi 

I am working on a script, which will get process information that are running from last 2 hours and services information in file.

My Try:

$process = @{}

gwmi win32_process |% {$process[$_.handle] = $_.getowner().user}

get-process |? { (($_.StartTime -ne $null) -and

         (([DateTime]::Now - $_.StartTime).TotalMinutes -le 120)) } | select processname,Id,starttime,@{l="Owner";e={$process[$_.id.tostring()]}} | export-csv $env:temp\process.txt -NoTypeInformation

 

$service = get-service | Select-object Status,DisplayName | Add-Content $env:temp\process.txt 

 

Output in file is below:

"ProcessName","Id","StartTime","Owner"

"chrome","7456","06-09-2015 22:30:16","aslesh.p"

"chrome","8292","06-09-2015 23:13:14","aslesh.p"

"chrome","8876","06-09-2015 22:07:08","aslesh.p"

"chrome","9168","06-09-2015 22:44:30","aslesh.p"

"chrome","9184","06-09-2015 21:26:46","aslesh.p"

"chrome","9712","06-09-2015 23:09:36","aslesh.p"

"SearchUI","9940","06-09-2015 22:09:10","aslesh.p"

@{Status=Stopped; DisplayName=McAfee Application Installer Cleanup (0241511441132241)}

@{Status=Stopped; DisplayName=AllJoyn Router Service}

@{Status=Stopped; DisplayName=Application Layer Gateway Service}

@{Status=Running; DisplayName=AMD External Events Utility}

@{Status=Stopped; DisplayName=Application Identity}

@{Status=Running; DisplayName=Application Information}

@{Status=Running; DisplayName=Apple Mobile Device Service}

 

Expected output is :

"ProcessName","Id","StartTime","Owner"

"chrome","7456","06-09-2015 22:30:16","aslesh.p"

"chrome","8292","06-09-2015 23:13:14","aslesh.p"

"chrome","8876","06-09-2015 22:07:08","aslesh.p"

"chrome","9168","06-09-2015 22:44:30","aslesh.p"

"chrome","9184","06-09-2015 21:26:46","aslesh.p"

"chrome","9712","06-09-2015 23:09:36","aslesh.p"

"SearchUI","9940","06-09-2015 22:09:10","aslesh.p"

 

"Status","DisplayName"

"Stopped","McAfee Application Installer Cleanup (0241511441132241)"

"Stopped","AllJoyn Router Service"

"Stopped","Application Layer Gateway Service"

"Running","AMD External Events Utility"

"Stopped","Application Identity"

"Running","Application Information"

"Running","Apple Mobile Device Service"

"Stopped","App Readiness"

 

May i know what all changes needs to be done??

Thanks in advance


Viewing all articles
Browse latest Browse all 6937

Trending Articles