Execute-ProcessAsUser
SYNOPSISโ
Execute a process with a logged in user account, by using a scheduled task, to provide interaction with user in the SYSTEM context.
SYNTAXโ
Execute-ProcessAsUser [[-UserName] <String>] [-Path] <String> [[-TempPath] <String>] [[-Parameters] <String>]
[-SecureParameters] [[-RunLevel] <String>] [-Wait] [-PassThru] [[-WorkingDirectory] <String>]
[[-ContinueOnError] <Boolean>] [<CommonParameters>]
DESCRIPTIONโ
Execute a process with a logged in user account, by using a scheduled task, to provide interaction with user in the SYSTEM context.
EXAMPLESโ
EXAMPLE 1โ
Execute-ProcessAsUser -UserName 'CONTOSO\User' -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"C:\Test\Script.ps1`"; Exit `$LastExitCode }" -Wait
Execute process under a user account by specifying a username under which to execute it.
EXAMPLE 2โ
Execute-ProcessAsUser -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"C:\Test\Script.ps1`"; Exit `$LastExitCode }" -Wait
Execute process under a user account by using the default active logged in user that was detected when the toolkit was launched.
PARAMETERSโ
-UserNameโ
Logged in Username under which to run the process from. Default is: The active console user. If no console user exists but users are logged in, such as on terminal servers, then the first logged-in non-console user.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: $RunAsActiveUser.NTAccount
Accept pipeline input: False
Accept wildcard characters: False
-Pathโ
Path to the file being executed.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-TempPathโ
Path to the temporary directory used to store the script to be executed as user. If using a user writable directory, ensure you select -RunLevel 'LeastPrivilege'.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Parametersโ
Arguments to be passed to the file being executed.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-SecureParametersโ
Hides all parameters passed to the executable from the Toolkit log file.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-RunLevelโ
Specifies the level of user rights that Task Scheduler uses to run the task. The acceptable values for this parameter are:
-
HighestAvailable: Tasks run by using the highest available privileges (Admin privileges for Administrators). Default Value.
-
LeastPrivilege: Tasks run by using the least-privileged user account (LUA) privileges.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: HighestAvailable
Accept pipeline input: False
Accept wildcard characters: False
-Waitโ
Wait for the process, launched by the scheduled task, to complete execution before accepting more input. Default is $false.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-PassThruโ
Returns the exit code from this function or the process launched by the scheduled task.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-WorkingDirectoryโ
Set working directory for the process.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ContinueOnErrorโ
Continue if an error is encountered. Default is $true.
Type: Boolean
Parameter Sets: (All)
Aliases:
Required: False
Position: 7
Default value: True
Accept pipeline input: False
Accept wildcard characters: False
CommonParametersโ
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.