Last Update: Sep 04, 2024 | Published: Sep 30, 2013
Welcome back, in this post we will continue where we left off on our last post on System Center 2012 Sp1 – Orchestrator and disk maintenance, completing our remaining runbooks and adding in some PowerShell to assist in the process.
With the Archive runbook already created, in this second post, we will guide our way through the remaining three runbooks needed to complete the project.
The second runbook I create will be called 2.3 Purge Files. This runbook will accept the details of the purge job, including the source and age of the files for purging.
On the canvas I will place and hook up the following:
Starting with the Initialize Data Activity I configure the following properties:
Next, on my Purge Files activity I define the following setting:
$groomingFolder = {SourcePath from “Initialize Data”}{SourceMask from “Initialize Data”} $groomingAge = {Age from “Initialize Data”} function Remove-Files { <# .SYNOPSIS This function will Remove files from your file system based on some simple paramaters .DESCRIPTION .PARAMETER .EXAMPLE Delete-Files \UNCPath -Recursive -RemoveFolders -DaysOld 30 -Testing #> [cmdletbinding()] param( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeLine= $true)] [string]$Path, [Parameter(Mandatory = $False)] [switch]$Recursive, [Parameter(Mandatory = $False)] [switch]$RemoveFolders, [Parameter(Mandatory = $False)] [switch]$Testing, [Parameter(Mandatory = $False)] [int]$DaysOld = 0 ) begin { $Now = Date $LastWrite = $Now.AddDays(-$DaysOld); Write-Verbose ("Starting Script...") Write-Verbose ("We will remove Files older than $DaysOld from the file System - Last Updated After $LastWrite ") if ($Recursive) { Write-Verbose ("We will Recurse trough the file System") } if ($RemoveFolders) { Write-Verbose ("We will Remove Folders as well as Files") } if ($Testing) { Write-Verbose ("Running in TEST MODE") } Write-Verbose ("Process starting at $Path") } process { if($Testing) { get-childitem $Path -Recurse:$Recursive | ? {$_.LastWriteTime -le "$LastWrite"} | ? {$_.PSIsContainer -eq $RemoveFolders} | select name, length } else { get-childitem $Path -Recurse:$Recursive | ? {$_.LastWriteTime -le "$LastWrite"} | ? {$_.PSIsContainer -eq $RemoveFolders} | Remove-Item } } } $error.clear() Remove-Files -Path $groomingFolder -Recursive -DaysOld $groomingAge $error
Finally, Select the Pipeline/Link from the Purge Files activity to the Failure activity, and set its properties
The next runbook I create will be called 2.1 Enumerate Maintenance Plan. This runbook will connect to our SQL table, and gather the list of tasks for orchestrator to process.
To implement this I am going to defined the following
Once I have all the activities on the canvas, connect the links as described in the plan.
Starting with the Run .NET Activity, rename the activity to Maintenance Variables, and then
configure its properties similar to the following:
$SQLServer = "PDC-DB-SQL01" $SQLDatabase = "ITServices" $SQLTable = "ITStorageMaintenancePlan"
Next, on the Query Database activity
SELECT [SourcePath], [SourceMask], [Action], [Age], [TargetPath] FROM [ITStorageMaintenancePlan]
Select the Pipeline/Link from the Query Database activity to the Archive Files activity, and set its properties
In a similar fashion, we will now configure the other link for Purge Jobs, begin by selecting the Pipeline/Link from the Query Database activity to the Purge Files activity, and set its properties.
Select our Archive runbook activity, and set its properties
Similarly, we can now also set the properties of the Purge runbook
The final runbook we are going to create is the trigger flow runbook. This will use a monitor style activity to trigger the main Job Enumeration runbook based on a time/date event, essentially a scheduled start. I am calling this runbook Monitor – 2. Trigger Disk Maintenance.
We will drag two activities to the canvas: a Monitor Date/Time activity followed by the Invoke Runbook Activity, which we will rename to Start Job Enumeration.
With these on the canvas we can create a simple link to connect these together.
On the Properties of the Monitor Date/Time activity
Select our Start Enumerate Maintenance Plan activity and set its properties.
Cool right? Over the last two posts we have created a very simple implementation with no logging or error handling, but have learned how to use different activities to run our jobs. In this post we also leveraged Powershell as part of one of the runbooks simply to illustrate the ease of mixing these technologies.
Go ahead and build this out in your test environment, and ill look forward to your comments. In the next post we will try another solution, until then – happy automations!