Using an ARS Script in a standard Windows Scheduler Task

It’s been ages since I last blogged as I’ve been busy regression testing all of my ARS 6.9 scripts on ARS 7.0 and while doing this bringing them all in line. The scripts have been written over the last 7 years and it’s unbelievable the changes in style that I have made from my first scripts to the latest.

I wrote an audit script that would alert me if an ARS scheduled task didn’t run or had an unexpected error, an oxymoron if I ever heard one, how could an error be anything but unexpected. This script worked well and emails me if any of the scheduled task has an issue.

But what if the audit script fails?

My solution was to run the same audit script on another server using the Windows Task Scheduler and of course this script also reports on the audit scheduled task and warns me if it didn’t run.

But what if I edit the ARS scheduled task script?

Last BUT I promise, I’m getting to the point.  I didn’t want to have to remember to update the script in multiple locations whenever a change was made.  My solution was to use the following two commands in a simple script hosted on the second windows server and run by the task scheduler that downloads the script from ARS and uses Invoke-Expression to run the script locally.

$scriptText = $(Get-QADObject “GUID of the ARS Script” -IncludedProperties edsaScriptText -connection $proxy).edsaScriptText

$returnMsg = Invoke-Expression $scriptText

You can even substitute lines of code using  $scriptText.replace  but be careful, debugging is not going to be easy.

A central store for scripts you could run on ARS or any other Windows sever using the same code

There are lots of ways of centralising your scripts ( Network Share, GPO ) but if you have to run them on both ARS and externally as in this case it’s ideal.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.