How to Schedule a PowerShell Script to Auto Run On a Windows Server

To read the full article click, How to Schedule a PowerShell Script to Auto Run On a Windows Server

If you want your PowerShell script to auto run at specific intervals you need to schedule the PowerShell script with Windows task scheduler. There are other tools you can use to schedule a PowerShell script to run at specified times but this guide demonstrates how to do this with the Windows task scheduler I will…

Hi Victor,
This is so great, finally I know how to auto - run a powershell script. :slight_smile:
Thank you so much.

What I don’t get this way, is the “result” of the script…
I use a simple script to ping a list of computers.
Manually triggered it tells me if the computers in the list are up or down.

Triggered via taskscheduler a window shows up for a fraction of a second, that’s it.

So the ping will happen automatically, what is great, but no visible result if a computer is up or down.

Is there any way to make the output of the script visible?

Thank you
Greetings from Germany
Marcus Keller

Hi @Marcus_K ,

Could you share the PS script you’re using so I can take a look? Also, if you could try describing what you want to achieve in some detail, that would be great.

The Script simply sends a ping via “test-connection”.
The text-file referred contains only IP’s and / or an address.

Purpose one:
Check if the IP is available.
Purpose two:
Establish a connection to the address. (We use a service that needs to pinged, to be reachable, first ping always fails, second or latest third is fine then).

The pings are sent, but I can’t see any result, even if the computer/IP is not reachable.
The “write host part” seems to close the window immediately after the script ran…

Here is the used skript:

#Check if computers are up

$computers = Get-Content -Path “C:\temp\ListOfComputerIP.txt”

foreach ($computer in $computers)

 { 

 $ip = $computer.Split(" - ")[0] 

 if (Test-Connection  $ip -Count 1 -ErrorAction SilentlyContinue){ 

     Write-Host "$ip is up" 

     } 

 else{ 

     Write-Host "$ip is down" 

     } 

 } 

Thank you :slight_smile:
Bye Marcus Keller

@Marcus_K sorry I am replying so late. You could do two things to make the result more visible:

  1. You could increase the -Count to something higher than 1
  2. You could write the result in the else {} statement to a text file. This is what I recommend. So, instead of getting the result on the screen, you can look at the text file to see the computers that are down.

Additionally, since the script runs on schedule, generates the name of the text file automatically. For example, you could use Get-Date to generate the name of the text file.

Hello Victor,

this is great and valuable advice. :slight_smile:
Thank you.

I tried Start-Transcript and Stop-Transcript in the meantime, what gives me a protocoll, just like you adviced.
I also increased the ping attempts to 6.

If I run the script manually it works perfect. I can see the output in the Powershell Terminal-Window, and get the transcript file in my documents.

But if I trigger the script via Task-planer there’s no transcript file and the Terminal window shows up only for a second, even with some red writing.

My hunch is, started via taskplaner, it might need some different permissions or something?

Do you have any idea, why the script won’t work startet via Taskplaner?

Thank you

Bye Marcus Keller