# Scheduled task using gMSA

**URL:** <https://forums.powershell.org/t/scheduled-task-using-gmsa/14262>\
**Category:** PowerShell Help\
**Created:** [April 27, 2020, 1:09am UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262 "2020-04-27T01:09:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![poison](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@poison](https://forums.powershell.org/u/poison)\
**Post date:** [April 27, 2020, 1:09am UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262/1 "2020-04-27T01:09:01Z")

</div>

Hello,

As it is not possible to use GUI for creating a scheduled task on Windows when using gMSA I must user Powershell.  
What I have done is : creating my task using GUI whith administrator account then I have changed the user using this command

[pre] **$principal = New-ScheduledTaskPrincipal -UserID Domain\GMServiceAccount$ -LogonType Password**

**Set-ScheduledTask “Task Name” -Principal $principal[/pre]**

It works fine for 1 server but I need to use it to multiple servers.  
Si I have exported my task by GUI and imported it using this PS command :

[pre]**Register-ScheduledTask -xml (Get-Content ‘C:\PATH\TO\IMPORTED-FOLDER-PATH\TASK-INPORT-NAME.xml’ | Out-String) -TaskName “TASK-IMPORT-NAME” -User Domain\GMServiceAccount$ –Force[/pre]**

My issue appeared at this time because after importing my task on another server some parameters have changed.  
My task has been created to run “whether user is logged on or not” but after the importation this parameters changes to “Run only when user is logged on”.

Do you have any idea about what I can do ?

Regards,

&nbsp;

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [April 28, 2020, 10:20pm UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262/2 "2020-04-28T22:20:21Z")

</div>

Here’s a script I came up with to create scheduled tasks. Maybe it can help you finish yours.

```
$Scriptblock = {
    $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -windowstyle hidden c:\path\to\script.ps1'
    $trigger = New-ScheduledTaskTrigger -Daily -At 7am
    $settings = New-ScheduledTaskSettingsSet -Hidden -WakeToRun -StartWhenAvailable
    $params = @{
        Action = $action
        Trigger = $trigger
        TaskName = "Scheduled task name"
        User = 'domain\user'
        Description = "Description of scheduled task"
        Settings = $settings
        Password = 'OhNoClearText'
    }
    Register-ScheduledTask @params
}
Invoke-Command -ComputerName RemotePC -ScriptBlock $Scriptblock
```

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [April 28, 2020, 10:24pm UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262/3 "2020-04-28T22:24:38Z")

</div>

Oh this might be more helpful. I think it’s the fact of providing the username and setting the logontype that you are needing.

```
$principal = New-ScheduledTaskPrincipal -RunLevel Highest -UserId Domain\User -LogonType InteractiveOrPassword
```

---

<div class="post-metadata">

**Author:** ![poison](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@poison](https://forums.powershell.org/u/poison)\
**Post date:** [April 29, 2020, 1:37am UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262/4 "2020-04-29T01:37:44Z")

</div>

Hi Doug,

You think that what I want to do is not possible ?  
Create a task from GUI \> modify it by PS \> export the task by GUI \> import the task by PS to another server ?

You think that I should create the task by PS to all my servers ?

Regards,

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [April 29, 2020, 2:25am UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262/5 "2020-04-29T02:25:50Z")

</div>

I think you could do it either way. I’m just showing you what I used to set my task to run as a user whether logged in or not. So one of those settings should do what you want. Good luck!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/scheduled-task-using-gmsa/14262/6 "2024-05-16T20:29:48Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


