Register-ScheduledTask : The parameter is incorrect.


  1. Posts : 36
    windows10
       #1

    Register-ScheduledTask : The parameter is incorrect.


    Code i used:
    Code:
    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}`""
      Exit
    }
    
    $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.
    [Console]::ReadKey()
    Result:
    Code:
    Register-ScheduledTask : The parameter is incorrect.
    (23,8):UserId:
    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 : 1,041
    Windows 7
       #2

    Your script breaks when passed an username which doesn't exist locally.
    $User = If ($Args[0]) {$Args[0]} Else {[Environment]::UserName
    Code:
    PS C:\Users\GARLIN\Downloads> .\Untitled1.ps1 NOTREALUSER
    Register-ScheduledTask : No mapping between account names and security IDs was done.
    (23,8):UserId:
    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
     
    Done.
    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 14:04.
Find Us




Windows 10 Forums