It would appear that the task scheduler does not like 2 character user names.
Edd works but Ed doesn't.
PS C:\> Get-LocalUser -Name e*
Name Enabled Description
---- ------- -----------
ed True
edd True
PS C:\> $name = "Test1zzz"
PS C:\> Unregister-ScheduledTask -TaskName $name -Confirm:$false -ea SilentlyContinue
PS C:\> $action = New-ScheduledTaskAction -Execute "C:\temp\blabla.exe"
PS C:\> $trig = New-ScheduledTaskTrigger -once -at "12am"
PS C:\> $prin = New-ScheduledTaskPrincipal -UserId "ed"
PS C:\> Register-ScheduledTask -TaskName $name -Action $action -Trigger $trig -Principal $prin
Register-ScheduledTask : The task XML contains a value which is incorrectly formatted or out of range.
(45,4):Task:
At line:1 char:1
+ Register-ScheduledTask -TaskName $name -Action $action -Trigger $trig ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041318,Register-ScheduledTask
PS C:\> $task = Get-ScheduledTask -TaskName $name -ea SilentlyContinue
PS C:\> $task.Description = "Updated desc."
The property 'Description' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $task.Description = "Updated desc."
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
PS C:\> $task | Set-ScheduledTask -ErrorAction SilentlyContinue
PS C:\>
PS C:\> Unregister-ScheduledTask -TaskName $name -Confirm:$false -ea SilentlyContinue
PS C:\> $action = New-ScheduledTaskAction -Execute "C:\temp\blabla.exe"
PS C:\> $trig = New-ScheduledTaskTrigger -once -at "12am"
PS C:\> $prin = New-ScheduledTaskPrincipal -UserId "edd"
PS C:\> Register-ScheduledTask -TaskName $name -Action $action -Trigger $trig -Principal $prin
TaskPath TaskName State
-------- -------- -----
\ Test1zzz Ready
PS C:\> $task = Get-ScheduledTask -TaskName $name
PS C:\> $task.Description = "Updated desc."
PS C:\> $task | Set-ScheduledTask
TaskPath TaskName State
-------- -------- -----
\ Test1zzz Ready
PS C:\>
Schtasks has the same issue.
PS C:\> Unregister-ScheduledTask -TaskName Test1zzz -Confirm:$false -ea SilentlyContinue
PS C:\> schtasks.exe /create /tn Test1zzz /ru ed /sc once /st 23:01 /tr C:\temp\blabla.exe
ERROR: The task XML contains a value which is incorrectly formatted or out of range.
(39,4):Task:
PS C:\>
PS C:\> Unregister-ScheduledTask -TaskName Test1zzz -Confirm:$false -ea SilentlyContinue
PS C:\> schtasks.exe /create /tn Test1zzz /ru edd /sc once /st 23:01 /tr C:\temp\blabla.exe
SUCCESS: The scheduled task "Test1zzz" has successfully been created.
PS C:\>
BUT!!!!!!!!! If you add the computername to the local account, it will work.
PS C:\> $name = "Test1zzz"
PS C:\> Unregister-ScheduledTask -TaskName $name -Confirm:$false -ea SilentlyContinue
PS C:\> $action = New-ScheduledTaskAction -Execute "C:\temp\blabla.exe"
PS C:\> $trig = New-ScheduledTaskTrigger -once -at "12am"
PS C:\> $prin = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\ed"
PS C:\> Register-ScheduledTask -TaskName $name -Action $action -Trigger $trig -Principal $prin
TaskPath TaskName State
-------- -------- -----
\ Test1zzz Ready
PS C:\> $task = Get-ScheduledTask -TaskName $name -ea SilentlyContinue
PS C:\> $task.Description = "Updated desc."
PS C:\> $task | Set-ScheduledTask -ErrorAction SilentlyContinue
PS C:\>
SilentlyContinue
PS C:\> $action = New-ScheduledTaskAction -Execute "C:\temp\blabla.exe"
PS C:\> $trig = New-ScheduledTaskTrigger -once -at "12am"
PS C:\> $prin = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\edd"
PS C:\> Register-ScheduledTask -TaskName $name -Action $action -Trigger $trig -Principal $prin TaskPath TaskName State -------- -------- ----- \ Test1zzz Ready
PS C:\> $task = Get-ScheduledTask -TaskName $name
PS C:\> $task.Description = "Updated desc."
PS C:\> $task | Set-ScheduledTask
TaskPath TaskName State
-------- -------- -----
\ Test1zzz Ready
PS C:\>
PS C:\>
PS C:\>
PS C:\> Unregister-ScheduledTask -TaskName Test1zzz -Confirm:$false -ea SilentlyContinue
PS C:\> schtasks.exe /create /tn Test1zzz /ru "blackhole\ed" /sc once /st 23:01 /tr C:\temp\blabla.exe
SUCCESS: The scheduled task "Test1zzz" has successfully been created.
PS C:\>
From the gui, it will show up as Ed, Reselect the user so that it contains the computer name.