Schedule Tasks

Welcome Forums General PowerShell Q&A Schedule Tasks

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 9 months ago.

  • Author
  • #76587

    Topics: 11
    Replies: 6
    Points: 0
    Rank: Member

    I'm running into a problem where I'm writing an "Onboarding" script for Windows 10 and using Schedule Tasks to run the next PoSh script after a reboot and auto login. It works fine if it never joins the domain which defeats the purpose. Below is the error I am getting with the code

    function Invoke-PrepareScheduledTask
    $actionscript = '-NonInteractive -WindowStyle Normal -NoLogo -NoProfile -NoExit  -Command "&''c:\temp\onboarding\ps\restart.ps1''"'
    $pstart =  "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    $act = New-ScheduledTaskAction -Execute $pstart -Argument $actionscript
    $trig = New-ScheduledTaskTrigger -RandomDelay (New-TimeSpan -Minutes 5) -AtLogon
    Get-ScheduledTask -TaskName joindomain | Unregister-ScheduledTask -Confirm:$false
    Register-ScheduledTask -TaskName "restart" -Action $act -Trigger $trig -User $encrypteduser -Password $convertedpw

    When it fires this off I get the below error. The computer joins the domain as it logins after the reboot automatically under the domain account

    Register-ScheduleTask : The security database on the server does not have a computer account for this workstation trust relationship.
    +Register-ScheduleTask -TaskName "restart" -Action $act -Trigger $tri....
    +CategoryInfo  : NotSpecified (PS_ScheduleTask:Root/Microsoft/...S_ScheduleTask)
    +FullQualifyErrorId: HRESULT 0x800706fb, Register-ScheduleTask
  • #76812

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    That's because after a computer joins a domain, it has a different identity. That's a design feature of Windows; you'll probably have to find some other way around the problem.

The topic ‘Schedule Tasks’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort