PowerShell
Edytuj|UsuĊ„
Function Find-TaskServiceUser { 
<# 
.SYNOPSIS 
Finding scheduled tasks, system services on computer by user name.  
.DESCRIPTION 
Finding scheduled tasks, system services on local or remote computer by given user name.  
'Administrator' and local computer are default values. 
The results can be redirected to the log file (see 'log' parameter). 
.PARAMETER User 
User name to find scheduled tasks or system services. Default value is 'Administrator'. 
.PARAMETER Computer 
Computer to find tasks/services. Default value is 'localhost' ($env:COMPUTERNAME). 
.PARAMETER Task 
A Switch to look for scheduled tasks where user name is matched. 
.PARAMETER Service 
A Switch to look for system services where user name is matched. 
.PARAMETER Minimal 
A switch to enable minimalistic results. Object containing the computer name, number of tasks and/or number of services only. With -Log information about log file path is displayed but log file is not minimal. The return value is en object. 
.PARAMETER Export 
Enable exporting results objects to file (using "Export-Clixml"). Export file path is defined in "Exportpath" parameter. 
.PARAMETER Exportpath 
File name path to export results finding scheduled tasks and/or system services. 
.PARAMETER Log 
A switch to enable logging of output data to a log file. The log file with the path is defined in "LogFile" parameter. 
.PARAMETER Logfile 
Path with file name where logging output. Default value is [$env:TEMP]\find-taskserviceuser.log. Works only with Log switch. 
.EXAMPLE 
PS> Find-TaskServiceUser -Computer "WSRV00" -User "BobbyK" -Service -Task -Log 
 
Description 
----------- 
Find system services and scheduled tasks on "WSRV00" for user name is matched "BobbyK". Logging is enabled. 
.EXAMPLE 
PS> "WSRV01","WSRV02" | Find-TaskServiceUser -Service -Task 
 
Description 
----------- 
Find system services and scheduled tasks on computers "WSRV01", "WSRV02"  where user name is matched "Administrator". 
.EXAMPLE 
PS> "WSRV01","WSRV10" | Find-TaskServiceUser -Service -Task -Export 
PS> $data = Import-Clixml "C:\Users\test_user\Documents\Find-TaskServiceUser.XML" 
PS> $data.Tasks | Format-Table -Autosize 
PS> $data.Services | Format-Table -Autosize 
 
Description 
----------- 
Find system services and scheduled tasks on computers "WSRV01", "WSRV10" where user name is matched "Administrator". Results are exported to XML file and then imported to $data variable. Results are displayed. 
.LINK 
https://github.com/voytas75/Find-TaskServiceUser 
.LINK 
https://www.powershellgallery.com/packages/Find-TaskServiceUser 
.NOTES 
ICON CREDITS: Module icon made by [Freepik](https://www.freepik.com/) from [Flaticon](https://www.flaticon.com/) is licensed [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/) 
#> 
...

It is a powerfull powershell module for finding scheduled tasks and system services on a local or remote computer that are created or 'run as a given' user. Result can be displayed, stored in variable as object. There is parameter -Minimal to enable minimalistic results containing computer name, number of tasks and/or number of services only. You can -Log and -Export results. The search for tasks is carried out in two ways: Get-ScheduleTask and system command: "schtasks".

For more info visit my project website on GitHub - https://github.com/voytas75/Find-TaskServiceUser


Find-TaskServiceUser

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Install module

Copy and Paste the following command to install this package using PowerShellGet.


Install-Module -Name Find-TaskServiceUser

Examples

  1. Find system services and scheduled tasks on "WSRV00" for user "BobbyK" with logging output to a file:

    Find-TaskServiceUser -Computer "WSRV00" -User "BobbyK" -Service -Task -Log 
  2. Find system services and scheduled tasks on computers "WSRV01", "WSRV02" for user "Administrator":

    "WSRV01","WSRV02" | Find-TaskServiceUser -Service -Task 
  3. Find system services and scheduled tasks on computers "WSRV01", "WSRV02", "WSRV03" for user "BobbyK":

    @("WSRV01","WSRV02"), "WSRV03" | Find-TaskServiceUser -Task -User "BobbyK" 
  4. Find tasks and services on server "WSRV04" for "SYSTEM" user and return as a minimalistic result in $object variable:

    $object = Find-TaskServiceUser -Task -Service -Server "WSRV04" -User "SYSTEM" -Minimal 
    $object