Showing posts with label System Center. Show all posts
Showing posts with label System Center. Show all posts

Wednesday, February 8, 2012

Using System Center Orchestrator 2012 to monitor folders

One big drawback with the existing "Monitor Folder" activity in System Center Orchestrator 2012 RC is that it will only trigger on files dropped while your runbook is actually running. That means that if you temporarily stop your runbook to do an adjustment, all files that some other system drops in your folder while doing this will be ignored when you start your runbook again.

It's pretty easy to avoid this by instead scheduling a powershell script that returns all files in your folder.
Here's a simple example:

Start by adding a Monitor Date/Time activity and set an appropriate polling interval. I'll set mine to 1 minute.


Next add a "Run .Net Script" activity and link that to the monitor acitivity. Select PowerShell as language and paste this into the script window (modify it to your own lab folder). The *copy* file mask is by the way a handy tip when developing these kind of workflows. Using this you will be able to keep a file in your dev directory and just copy-paste it in the same directory to kick your workflow.

$FileName = (Get-ChildItem c:\temp\lab\*copy*.xml) | Select-Object FullName
$Count=@(Get-ChildItem c:\temp\lab\*copy*.xml).Count

The $Count parameter will be used to decide whether or not to continue and the $FileName parameter will be used to perform some kind of operations on that file.



Now set the data that will be published:


Now you're all set to continue building your runbook. In my example i will just copy the file to another location. On the link set the following condition




Now add the copy file activity. 

As you may note I do a little magic on the FileName parameter…Here’s a better view on that




This is what my runbook looks like. I also log when no files are found in this example (set NumberOfFiles equals 0 on the link if you want to do that as well)