An open API service indexing awesome lists of open source software.

https://github.com/michaelschoenburg/runtaskasuser

This Script runs a task in the context of another UserName.
https://github.com/michaelschoenburg/runtaskasuser

powershell powershell-script task-scheduler terminalserver windows

Last synced: about 2 months ago
JSON representation

This Script runs a task in the context of another UserName.

Awesome Lists containing this project

README

          

`Get-Help .\RunTaskAsUser.ps1 -Full`

```
NAME
RunTaskAsUser.ps1

SYNOPSIS
This Script runs a task in the context of another UserName.


SYNTAX
C:\Users\mschoenburg.CENTER\Desktop\RunTaskAsUser.ps1 [-UserName] [-PathToFile] [[-Arguments] ] [-Computer ] []


DESCRIPTION
This Script uses the task scheduler to create a new task in the context of specified UserName, runs it immediately after and deletes it in the end.

PARAMETERS
-UserName
The UserName in whose context the File should be executed.

Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false

-PathToFile
The File that is to be executed

Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Arguments
The Arguments that should be passed along to the File.

Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Computer
The computer/server this should happen on.
Defaults to localhost.

Required? false
Position? named
Default value ($env:computername)
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS
See parameters.
OUTPUTS
None.


NOTES


Author: Michael Schönburg
Current version: 0.1
Last change: 08.06.2021

-------------------------- EXAMPLE 1 --------------------------

PS C:\>& 'C:\TMP\RunTaskAsUserName.ps1' -UserName 'mschoenburg' -PathToFile 'C:\TMP\screenshot.lnk' -Computer 'My-RDS-01'
This runs the link screenshot.lnk in the context of the UserName mschoenburg on the terminal server My-RDS-01.






-------------------------- EXAMPLE 2 --------------------------

PS C:\>& 'C:\TMP\RunTaskAsUserName.ps1' -UserName 'mschoenburg' -PathToFile 'C:\TMP\MyProgram.exe'
This would be executed on the local machine.






-------------------------- EXAMPLE 3 --------------------------

PS C:\>& 'C:\TMP\RunTaskAsUserName.ps1' -UserName 'mschoenburg' -PathToFile 'C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE' -Arguments '/safe'
This would start outlook in safe mode.







```