Register-ScheduledTask : The parameter is incorrect.

  1. Posts : 36

    Register-ScheduledTask : The parameter is incorrect.

    Code i used:
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
      # Relaunch as an elevated process
      $User = [Environment]::UserName
      $Script = $MyInvocation.MyCommand.Path
      Start-Process powershell.exe -Verb RunAs "-ExecutionPolicy RemoteSigned -File `"$PSCommandPath`" `"${User}`""
    $Action   = New-ScheduledTaskAction -Execute "$PSScriptRoot\LibreWolf-WinUpdater.exe" -Argument "/Scheduled"
    $Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -RunOnlyIfNetworkAvailable
    $4Hours   = New-ScheduledTaskTrigger -Once -At (Get-Date -Minute 0 -Second 0).AddHours(1) -RepetitionInterval (New-TimeSpan -Hours 4)
    $AtLogon  = New-ScheduledTaskTrigger -AtLogOn
    $AtLogon.Delay = 'PT1M'
    $User     = If ($Args[0]) {$Args[0]} Else {[Environment]::UserName}
    Register-ScheduledTask -TaskName "LibreWolf WinUpdater ($User)" -Action $Action -Settings $Settings -Trigger $4Hours,$AtLogon -User $User -RunLevel Highest –Force
    Write-Output Done.
    Register-ScheduledTask : The parameter is incorrect.
    At C:\Program Files\LibreWolf\ScheduledTask-Create.ps1:17 char:1
    + Register-ScheduledTask -TaskName "LibreWolf WinUpdater ($User)" -Acti ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule
       dTask], CimException
        + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask
    Why the error? It worked before and it works on my other machine with the same windows version.
      My Computer

  2. Posts : 762
    Windows 7

    Your script breaks when passed an username which doesn't exist locally.
    $User = If ($Args[0]) {$Args[0]} Else {[Environment]::UserName
    PS C:\Users\GARLIN\Downloads> .\Untitled1.ps1 NOTREALUSER
    Register-ScheduledTask : No mapping between account names and security IDs was done.
    At C:\Users\GARLIN\Downloads\Untitled1.ps1:17 char:1
    + Register-ScheduledTask -TaskName "LibreWolf WinUpdater ($User)" -Acti ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
        + FullyQualifiedErrorId : HRESULT 0x80070534,Register-ScheduledTask
    Exception calling "ReadKey" with "0" argument(s): "Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read."
    At C:\Users\GARLIN\Downloads\Untitled1.ps1:21 char:1
    + [Console]::ReadKey()
    + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : InvalidOperationException
      My Computer


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:09.
Find Us

Windows 10 Forums