title: I need to schedule a job to run once at startup on Windows 2016 without a user logon
body: <p>I'm automating builds of windows servers in AWS (via packer and terraform).  I have a userdata script that changes the hostname when host is started and reboots after.
  My problem is that, after the system reboots, I need a software installation to happen (because it relies on the changed name.)</p>
  
  <p>I've tried something like this:</p>
  
  <pre><code>$RunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
  set-itemproperty $RunOnceKey "NextRun" ('C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -executionPolicy Unrestricted -File ' + "C:\mydir\after-boot\install_mysoftware.ps1")
  </code></pre>
  
  <p>The problem with this is that it only runs after a user login, which is unacceptable.
  So I read about RunServiceOnce, but when I try to use that in place of RunOnce, I get an error:</p>
  
  <pre><code>set-itemproperty : Cannot find path 'C:\Users\Administrator\HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce' 
  because it does not exist
  </code></pre>
  
  <p>How can I ensure my program runs once on system boot without waiting for a user login? Point/click won't work. I need a powershell solution to set this up.</p>