From 6d5fab175b6fb4517f3fb426ce80eb418166a837 Mon Sep 17 00:00:00 2001 From: Horacio Fernandez Date: Tue, 29 Jul 2014 14:35:11 -0500 Subject: [PATCH] Init --- .../RS_rsScheduledTask.psm1 | 76 ++++++++++++++++++ .../RS_rsScheduledTask.schema.mof | Bin 0 -> 934 bytes rsScheduledTask.psd1 | 31 +++++++ 3 files changed, 107 insertions(+) create mode 100644 DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.psm1 create mode 100644 DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.schema.mof create mode 100644 rsScheduledTask.psd1 diff --git a/DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.psm1 b/DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.psm1 new file mode 100644 index 0000000..844f6f3 --- /dev/null +++ b/DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.psm1 @@ -0,0 +1,76 @@ + Function Get-TargetResource { + param ( + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$ExecutablePath, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Params, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Name, + [ValidateSet("MINUTE", "HOURLY", "DAILY", "WEEKLY", "ONSTART", "ONLOGON")][string]$IntervalModifier = "MINUTE", + [ValidateSet("PRESENT", "ABSENT")][string]$Ensure = "PRESENT", + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][int]$Interval = 5 + ) + @{ + ExecutablePath = $ExecutablePath; + Params = $Params; + Name = $Name; + IntervalModifier = $IntervalModifier; + Ensure = $Ensure; + Interval = $Interval; + } + } + + Function Test-TargetResource { + param ( + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$ExecutablePath, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Params, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Name, + [ValidateSet("MINUTE", "HOURLY", "DAILY", "WEEKLY", "ONSTART", "ONLOGON")][string]$IntervalModifier = "MINUTE", + [ValidateSet("PRESENT", "ABSENT")][string]$Ensure = "PRESENT", + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][int]$Interval = 5 + ) + $tasks = Get-ScheduledTask + + if($tasks -contains $Name) { + return $true + } + else { + return $false + } + + } + + Function Set-TargetResource { + param ( + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$ExecutablePath, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Params, + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Name, + [ValidateSet("MINUTE", "HOURLY", "DAILY", "WEEKLY", "ONSTART", "ONLOGON")][string]$IntervalModifier = "MINUTE", + [ValidateSet("PRESENT", "ABSENT")][string]$Ensure = "PRESENT", + [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][int]$Interval = 5 + ) + $tasks = Get-ScheduledTask + + if($Ensure -eq "ABSENT") { + if($tasks -contains $Name) { + Write-Verbose "Deleting Scheduled Task $Name" + try{ + schtasks.exe /delete /tn $Name /f + } + catch { + Write-EventLog -LogName DevOps -Source RS_rsScheduledTask -EntryType Error -EventId 1002 -Message "Failed to delete scheduled task $Name `n $_.Exception.Message" + } + } + } + + if($Ensure -eq "PRESENT") { + if($tasks -notcontains $Name) { + Write-Verbose "Creating New Scheduled Task $Name $ExecutablePath $Params" + try{ + schtasks.exe /create /tn $Name /tr $($ExecutablePath, $Params -join ' ') /sc $IntervalModifier /mo $Interval /ru system /f + } + catch { + Write-EventLog -LogName DevOps -Source RS_rsScheduledTask -EntryType Information -EventId 1000 -Message "Failed to create scheduled task $Name `n $_.Exception.Message" + } + } + } + + } +Export-ModuleMember -Function *-TargetResource \ No newline at end of file diff --git a/DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.schema.mof b/DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.schema.mof new file mode 100644 index 0000000000000000000000000000000000000000..7da74ce7ef6a13ee05bcab89e42f5c9bf1a4e7ca GIT binary patch literal 934 zcmc(dUrPc}5XH}P(05q&sX(G$>#09R5}Q&{4-#Q|Gf~%A*Gj~%Uj1g$mRcd-Le|}x zd(N4ebLZo|sbdY)(wN_kf->Gcjg)FjvG%m1U4LS2tD;D!AbQ|Zb>K~P0e47jXyaa~ zttaA+CY;;*+SU7o>jjvBdL!y&CSsCVGPbHW@@@2UDn9r$4Zd>bTZeDhjAuv>WqbvWO{M85_;}1`J?Y(wzjVg6l_~;Zwn_5xz!@K%7^uM<-V)#ylrM! P(PJ6^d(N+YnJ>7X-MOD8 literal 0 HcmV?d00001 diff --git a/rsScheduledTask.psd1 b/rsScheduledTask.psd1 new file mode 100644 index 0000000..3661c7f --- /dev/null +++ b/rsScheduledTask.psd1 @@ -0,0 +1,31 @@ +@{ +# Version number of this module. +ModuleVersion = '1.0' + +# ID used to uniquely identify this module +GUID = '54a37b72-54a0-4bb5-9c5f-cd6fd84b28d8' + +# Author of this module +Author = 'Rackspace' + +# Company or vendor of this module +CompanyName = 'Rackspace' + +# Copyright statement for this module +Copyright = '(c) 2014 Rackspace. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'Module with DSC Resources for rsGit area' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '4.0' + +# Minimum version of the common language runtime (CLR) required by this module +CLRVersion = '4.0' + +# Functions to export from this module +FunctionsToExport = '*' + +# Cmdlets to export from this module +CmdletsToExport = '*' +} \ No newline at end of file