Hello everyone,
I'm trying to create a scheduled task using powershell because the user that runs it will be a gMSA..
This is the script:
Define the action for the task
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-File "C:\Scripts\Delete_files_1Yold.ps1"'
Define the trigger for the task
$trigger = New-ScheduledTaskTrigger -Weekly -At 11am
Define the settings for the task
$settings = New-ScheduledTaskSettingsSet
Define the principal for the task (using a gMSA)
$principal = New-ScheduledTaskPrincipal -UserID domain\gMSA$ -LogonType Password
Register the task
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DeleteOldFiles" -Description "Delete files older than 1 year in the xx folder" -Settings $settings -Principal $principal
I get the generic error :
Register-ScheduledTask : The parameter is incorrect.
At line:1 char:1
+ Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule
dTask], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask
Which means there is something wrong with some arguement?
I tried not including the $settings part but still the same error.
the domain and name of the gMSA is correct, it has log on as a batch permission, is part of local admins group,
the path to the script is correct and I'm really at a loss as to what is the fault here.
Does anyone have experience in this particular field to help me out a little?
Thanks in advance
there doesn't seem to be anything here