marcosbozzani/Win10ActiveHours

Register-ScheduledTask : The parameter is incorrect

Closed this issue · 5 comments

The task will not register running in an elevated powershell session on Windows 10 Enterprise. Full error Details:

Register-ScheduledTask : The parameter is incorrect.
(32,8):UserId:
At D:\win10activehours\setup.ps1:63 char:5

  •   Register-ScheduledTask $TaskName $TaskPath @options | Out-Null
    
  •   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + Category Info                  : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask
    
 Register-ScheduledTask $TaskName $TaskPath @options | Out-Null

Could you replace the above (line 63) with the following code and then post the output?

echo TaskName: $TaskName
echo TaskPath: $TaskPath
echo options: @options
Register-ScheduledTask $TaskName $TaskPath @options

Also, run winver in PowerShell to see with version of Win10 you're running (e.g. Version 1903 (OS Build 18362.418))

Altered Script Output:

TaskName:
Update
TaskPath:
\Win10ActiveHours
options:
-Principal:

DisplayName :
GroupId :
Id :
LogonType : S4U
RunLevel : Limited
UserId : <USER_OBSCURED>
ProcessTokenSidType : Default
RequiredPrivilege :
PSComputerName :

-Trigger:
Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition :
StartBoundary :
Delay :
Subscription : *[System[Provider[@name='Microsoft-Windows-Power-Troubleshooter'] and EventID=1]]
ValueQueries :
PSComputerName :

Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition :
StartBoundary :
Delay :
PSComputerName :

Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition :
StartBoundary : 2020-02-05T06:00:00Z
DaysInterval : 1
RandomDelay :
PSComputerName :

Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition :
StartBoundary : 2020-02-05T18:00:00Z
DaysInterval : 1
RandomDelay :
PSComputerName :

-Force:
True
-Action:
Id :
Arguments : -NoLogo -NonInteractive -WindowStyle Hidden -EncodedCommand CgAgACAAIAAgACQAawBlAHkAIAA9ACAAIgBIAEsA
TABNADoAXABTAE8ARgBUAFcAQQBSAEUAXABNAGkAYwByAG8AcwBvAGYAdABcAFcAaQBuAGQAbwB3AHMAVQBwAGQAYQB0AGUAXABV
AFgAXABTAGUAdAB0AGkAbgBnAHMAIgAKACAAIAAgACAAJABoAG8AdQByACAAPQAgACgAZwBlAHQALQBkAGEAdABlACkALgBoAG8A
dQByAAoAIAAgACAAIABpAGYAIAAoACQAaABvAHUAcgAgAC0AZwBlACAAMQA4ACAALQBvAHIAIAAkAGgAbwB1AHIAIAAtAGwAdAAg
ADYAKQAgAHsACgAgACAAIAAgACAAIAAgACAAUwBlAHQALQBJAHQAZQBtAFAAcgBvAHAAZQByAHQAeQAgACQAawBlAHkAIABBAGMA
dABpAHYAZQBIAG8AdQByAHMAUwB0AGEAcgB0ACAAMQA4AAoAIAAgACAAIAAgACAAIAAgAFMAZQB0AC0ASQB0AGUAbQBQAHIAbwBw
AGUAcgB0AHkAIAAkAGsAZQB5ACAAQQBjAHQAaQB2AGUASABvAHUAcgBzAEUAbgBkACAAMQAyAAoAIAAgACAAIAB9ACAACgAgACAA
IAAgAGUAbABzAGUAIAB7AAoAIAAgACAAIAAgACAAIAAgAFMAZQB0AC0ASQB0AGUAbQBQAHIAbwBwAGUAcgB0AHkAIAAkAGsAZQB5
ACAAQQBjAHQAaQB2AGUASABvAHUAcgBzAFMAdABhAHIAdAAgADYACgAgACAAIAAgACAAIAAgACAAUwBlAHQALQBJAHQAZQBtAFAA
cgBvAHAAZQByAHQAeQAgACQAawBlAHkAIABBAGMAdABpAHYAZQBIAG8AdQByAHMARQBuAGQAIAAwAAoAIAAgACAAIAB9AAoAIAAg
ACAAIABTAGUAdAAtAEkAdABlAG0AUAByAG8AcABlAHIAdAB5ACAAJABrAGUAeQAgAEkAcwBBAGMAdABpAHYAZQBIAG8AdQByAHMA
RQBuAGEAYgBsAGUAZAAgADEACgA=
Execute : powershell
WorkingDirectory :
PSComputerName :

-Settings:
AllowDemandStart : True
AllowHardTerminate : True
Compatibility : Win7
DeleteExpiredTaskAfter :
DisallowStartIfOnBatteries : False
Enabled : True
ExecutionTimeLimit : PT72H
Hidden : False
IdleSettings : MSFT_TaskIdleSettings
MultipleInstances : IgnoreNew
NetworkSettings : MSFT_TaskNetworkSettings
Priority : 7
RestartCount : 0
RestartInterval :
RunOnlyIfIdle : False
RunOnlyIfNetworkAvailable : False
StartWhenAvailable : True
StopIfGoingOnBatteries : False
WakeToRun : True
DisallowStartOnRemoteAppSession : False
UseUnifiedSchedulingEngine : True
MaintenanceSettings :
volatile : False
PSComputerName :

Register-ScheduledTask : The parameter is incorrect.
(32,8):UserId:
At D:\win10activehours\setup.ps1:66 char:5

  • Register-ScheduledTask $TaskName $TaskPath @options
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule
      dTask], CimException
    • FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask

\Win10ActiveHours\Update installed
\Win10ActiveHours\Update not found

WinVer shows Version 1909 Build 18363.592

The problem seems to be that the USERNAME environment variable is not set ($env:USERNAME) when the scripts runs.

You can try to replace $env:USERNAME with a valid username in the computer. In my computer, its my own user and the logon type is S4U. If this doesn't work, you can try diferent users and logon types to see what works on your PC.

Documentation about ScheduledTaskPrincipal:
https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtaskprincipal?view=win10-ps

Examples

New-ScheduledTaskPrincipal -UserId "LOCALSERVICE" -LogonType ServiceAccount
New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest

Changing the Principal definition to:

Principal = New-ScheduledTaskPrincipal -UserId "LOCALSERVICE" -LogonType ServiceAccount -RunLevel Highest

Seems to have worked.