You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
1.3 KiB

  1. <h1>PowerShell</h1>
  2. <p>You can use <a href="https://msdn.microsoft.com/en-us/powershell/mt173057.aspx">PowerShell</a>
  3. and Windows Task Scheduler to automate various tasks on a Windows system.
  4. From within a PowerShell script it is also easy to ping SITE_NAME.</p>
  5. <p>Here is a simple PowerShell script that pings SITE_NAME. When scheduled to
  6. run with Task Scheduler, it will essentially just send regular "I'm alive" messages.
  7. You can of course extend it to do more things.</p>
  8. <div class="highlight"><pre><span></span><span class="c1"># inside a PowerShell script:</span>
  9. Invoke-RestMethod PING_URL
  10. </pre></div>
  11. <p>Save the above to e.g. <code>C:\Scripts\healthchecks.ps1</code>.
  12. Then use the following command in a Scheduled Task to run the script:</p>
  13. <div class="highlight"><pre><span></span>powershell.exe -ExecutionPolicy bypass -File C:<span class="se">\S</span>cripts<span class="se">\h</span>ealthchecks.ps1
  14. </pre></div>
  15. <p>In simple cases, you can also pass the script to PowerShell directly,
  16. using the "-command" argument:</p>
  17. <div class="highlight"><pre><span></span><span class="c1"># Without an underlying script, passing the command to PowerShell directly:</span>
  18. powershell.exe -command <span class="p">&amp;</span><span class="o">{</span>Invoke-RestMethod PING_URL<span class="o">}</span>
  19. </pre></div>