-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathSet-SchTaskMsa.ps1
More file actions
37 lines (29 loc) · 1.04 KB
/
Copy pathSet-SchTaskMsa.ps1
File metadata and controls
37 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
.SYNOPSIS
Sets a Scheduled Task's runtime user as the given gMSA/MSA.
.FUNCTIONALITY
Scheduled Tasks
.INPUTS
An object with a TaskName string property.
.LINK
https://learn.microsoft.com/windows-server/identity/ad-ds/manage/group-managed-service-accounts/group-managed-service-accounts/group-managed-service-accounts-overview
.LINK
Set-ScheduledTask
.LINK
New-ScheduledTaskPrincipal
.EXAMPLE
Set-SchTaskMsa.ps1 'Backup VSCode settings' automation
Sets the tasks running user to the "automation" managed service account.
#>
#Requires -Version 7
#Requires -Modules ScheduledTasks
[CmdletBinding()] Param(
[Parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string] $TaskName,
[Parameter(Position=1,Mandatory=$true)][Alias('MSA','gMSA','UserId')][string] $ServiceAccount,
[switch] $HighestRunLevel
)
Process
{
Set-ScheduledTask -TaskName $TaskName -Principal (New-ScheduledTaskPrincipal -UserID $ServiceAccount `
-LogonType Password -RunLevel:($HighestRunLevel ? 'Highest' : 'Normal'))
}