Scheduled task using gMSA

Welcome Forums General PowerShell Q&A Scheduled task using gMSA

Viewing 4 reply threads
  • Author
    Posts
    • #222747
      Participant
      Topics: 2
      Replies: 3
      Points: 32
      Rank: Member

      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

      $principal = New-ScheduledTaskPrincipal -UserID Domain\GMServiceAccount$ -LogonType Password
      
      Set-ScheduledTask “Task Name” -Principal $principal

      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 :

      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

      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,

       

      • This topic was modified 1 month ago by Poison06.
    • #223521
      Participant
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      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
    • #223527
      Participant
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      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
    • #223629
      Participant
      Topics: 2
      Replies: 3
      Points: 32
      Rank: Member

      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,

    • #223644
      Participant
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      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!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.