RES AM 2012 SR4 with PowerShell 3.0 support

imageRecently RES Automation Manager 2012 SR4 was released. One of new features of this new service release is that you can now execute PowerShell 3.0 scripts with RES Automation Manager. An important side note is that PowerShell 3.0 has to be installed on the target device. Regarding PowerShell 3.0 you should keep in mind that if you install PowerShell 3.0 on a Windows Server 2008 (R2) or Windows 7 device you don’t get the same functionality as PowerShell 3.0 on Windows 8 and Windows Server 2012. This is because some cmdlets are designed for Windows 8 and Windows Server 2012. Here is an list of all the new cmdlets http://technet.microsoft.com/en-us/library/hh857339.aspx#BKMK_Core. For each cmdlet in the list it is noted on which platform you can use it.

In my demo environment I have RES Automation Manager 2012 SR4 installed on a Windows Server 2008 R2 machine, I have SQL 2008 R2 installed on the same box. My target device is a Windows 8 computer. The script I want to deploy will configure a Windows Scheduled task to start defrag in the background at 12:30.

$action = New-ScheduledTaskAction -Execute defrag.exe -Argument "C: /U /V"
$trigger = New-ScheduledTaskTrigger -Daily -At 12:30
$settings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries

Register-ScheduledTask -TaskName DeFrag `
                       -TaskPath "\Maintenance" `
                       -Action $action `
                       -Trigger $trigger `
                       -User "study\administrator" `
                       -Password ‘Passw0rd’ `
                       -Settings $settings

RES Automation Manager 2012 easily gives you the possibility to make this script reusable. You can make this script to a job that makes it possible to create a scheduled task with every setting you want.

To make this possible we create parameters for every choice we made in the script. When you execute a job with these parameters you are triggered to enter values for these parameters.

First we are going to create a module, with a PowerShell task.
image

image

In the security context field we enter the credentials for an account with admin rights. Select “Use Windows PowerShell script from “Script” tab. With the checkbox “Override execution policy for this task”, you don’t have to think about the execution policy on your endpoint devices. After the task is done the execution policy is restored. Below the header prerequisites in this window it is stated that PowerShell version 1.0 has to be installed on the target computer. In the task we are about to execute this prerequisites is extended because we are using an PowerShell version 3.0 script.

image

In the above window you can see our script extended with the RES Automation Manager Module parameters, the parameters are shaded yellow.

image

In the window above you can see how the parameters from the previous screen are declared. You can see that there are different types of parameters. You can see the types, Text, List and Password

image

When you schedule the newly created module you notice the orange exclamation mark on the second tab. When click on this tab you’ll see the window below.

image

You can enter all the requested information. It is important to supply information about the data you want to be entered. It is important to know that if you create an parameter with the type Password, the entered data is not displayed in clear text.

image

In the window above you see the entered data for the pa
rameters. These parameters are parsed to the PowerShell script when this task is executed.

image

When the task is finished, and you double click on the executed task and you click on the tab Console Output you get to see what you would see normally when you execute the script at the beginning of this blog. 

image

When we logon to our target device and we navigate to the Task Scheduler you will see the scheduled task we have just created.

Was once an enthusiastic PepperByte employee but is now working at Ivanti. His blogs are still valuable to us and we hope to you too.