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

4 years ago
4 years ago
4 years ago
  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="powershell highlight"><pre><span></span><code><span class="c"># inside a PowerShell script:</span>
  9. <span class="nb">Invoke-RestMethod</span> <span class="n">PING_URL</span>
  10. </code></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="bat highlight"><pre><span></span><code>powershell.exe -ExecutionPolicy bypass -File C:\Scripts\healthchecks.ps1
  14. </code></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="bat highlight"><pre><span></span><code># Without an underlying script, passing the command to PowerShell directly:
  18. powershell.exe -command <span class="p">&amp;</span>{Invoke-RestMethod PING_URL}
  19. </code></pre></div>