Tag Archives: MimboloveWindows Scheduled Tasks

Failed to run PowerShell script via Task Scheduler on a 64 bit Windows

Written by Tao Yang

I came across a situation the other day that on a Windows Server 2008 R2 box, when I created a Scheduled Task to run a Powershell script, it runs OK using “C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe” (64 bit PowerShell) but fails with error code (0x1) if I use “C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell.exe” (32 bit Powershell)

I have done the following steps to help me troubleshoot the issue.

1. I have changed the scheduled task to “Run only when user is logged on” so a command prompt was shown when the task runs. I screen captured the output:

image

It looks like the PowerShell Execution Policy is preventing the script to run.

2. I confirmed the execution policy setting is set to RemoteSigned – which is sufficient for the script to run.

image

3. However, when I launched “Windows PowerShell (x86)”, I got different setting!

image

4. I didn’t know that we can have different Execution Policy for 64 Bit and 32 Bit PowerShell:

image

5. So to fix the problem was fairly easy – Set Execution Policy to RemoteSigned on a 32 bit PowerShell console.

As we know that the PowerShell Execution Policy setting is stored in the registry  HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Micorosft.Powershell\ExecutionPolicy

image

The 32 bit setting is stored in another location: HKLM\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

image

If the value “ExecutionPolicy” is missing, the default setting is “Restricted”. once I set the it to RemoteSigned, the ExecutionPolicy is created and set to RemoteSigned. If I delete it again, the execution policy is then changed back to “Restricted”

I don’t know what is the idea behind having 2 separate execution policies for 64 bit and 32 bit Powershell, maybe someone can share more information with us…

Windows Scheduled Tasks inventory – Using PowerShell

Written by Tao Yang

I originally posted this script here. It is to audit and inventory all scheduled tasks created for all windows computers under a specific OU in AD.

It has become useful for me again this week while I was working on a client’s SCOM environment. This particular client had no control over scheduled server reboots and they are not using SCOM Maintenance mode at all. Therefore there are a lot of SCOM alerts generated…

This script came in handy and it’s a good starting point to get all scheduled tasks and find out which ones are causing servers to reboot so we can start putting them into maintenance mode during reboot.