Skip to content

Commit 6d5fab1

Browse files
author
Horacio Fernandez
committed
Init
1 parent 8442949 commit 6d5fab1

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Function Get-TargetResource {
2+
param (
3+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$ExecutablePath,
4+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Params,
5+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Name,
6+
[ValidateSet("MINUTE", "HOURLY", "DAILY", "WEEKLY", "ONSTART", "ONLOGON")][string]$IntervalModifier = "MINUTE",
7+
[ValidateSet("PRESENT", "ABSENT")][string]$Ensure = "PRESENT",
8+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][int]$Interval = 5
9+
)
10+
@{
11+
ExecutablePath = $ExecutablePath;
12+
Params = $Params;
13+
Name = $Name;
14+
IntervalModifier = $IntervalModifier;
15+
Ensure = $Ensure;
16+
Interval = $Interval;
17+
}
18+
}
19+
20+
Function Test-TargetResource {
21+
param (
22+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$ExecutablePath,
23+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Params,
24+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Name,
25+
[ValidateSet("MINUTE", "HOURLY", "DAILY", "WEEKLY", "ONSTART", "ONLOGON")][string]$IntervalModifier = "MINUTE",
26+
[ValidateSet("PRESENT", "ABSENT")][string]$Ensure = "PRESENT",
27+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][int]$Interval = 5
28+
)
29+
$tasks = Get-ScheduledTask
30+
31+
if($tasks -contains $Name) {
32+
return $true
33+
}
34+
else {
35+
return $false
36+
}
37+
38+
}
39+
40+
Function Set-TargetResource {
41+
param (
42+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$ExecutablePath,
43+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Params,
44+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Name,
45+
[ValidateSet("MINUTE", "HOURLY", "DAILY", "WEEKLY", "ONSTART", "ONLOGON")][string]$IntervalModifier = "MINUTE",
46+
[ValidateSet("PRESENT", "ABSENT")][string]$Ensure = "PRESENT",
47+
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][int]$Interval = 5
48+
)
49+
$tasks = Get-ScheduledTask
50+
51+
if($Ensure -eq "ABSENT") {
52+
if($tasks -contains $Name) {
53+
Write-Verbose "Deleting Scheduled Task $Name"
54+
try{
55+
schtasks.exe /delete /tn $Name /f
56+
}
57+
catch {
58+
Write-EventLog -LogName DevOps -Source RS_rsScheduledTask -EntryType Error -EventId 1002 -Message "Failed to delete scheduled task $Name `n $_.Exception.Message"
59+
}
60+
}
61+
}
62+
63+
if($Ensure -eq "PRESENT") {
64+
if($tasks -notcontains $Name) {
65+
Write-Verbose "Creating New Scheduled Task $Name $ExecutablePath $Params"
66+
try{
67+
schtasks.exe /create /tn $Name /tr $($ExecutablePath, $Params -join ' ') /sc $IntervalModifier /mo $Interval /ru system /f
68+
}
69+
catch {
70+
Write-EventLog -LogName DevOps -Source RS_rsScheduledTask -EntryType Information -EventId 1000 -Message "Failed to create scheduled task $Name `n $_.Exception.Message"
71+
}
72+
}
73+
}
74+
75+
}
76+
Export-ModuleMember -Function *-TargetResource
934 Bytes
Binary file not shown.

rsScheduledTask.psd1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@{
2+
# Version number of this module.
3+
ModuleVersion = '1.0'
4+
5+
# ID used to uniquely identify this module
6+
GUID = '54a37b72-54a0-4bb5-9c5f-cd6fd84b28d8'
7+
8+
# Author of this module
9+
Author = 'Rackspace'
10+
11+
# Company or vendor of this module
12+
CompanyName = 'Rackspace'
13+
14+
# Copyright statement for this module
15+
Copyright = '(c) 2014 Rackspace. All rights reserved.'
16+
17+
# Description of the functionality provided by this module
18+
Description = 'Module with DSC Resources for rsGit area'
19+
20+
# Minimum version of the Windows PowerShell engine required by this module
21+
PowerShellVersion = '4.0'
22+
23+
# Minimum version of the common language runtime (CLR) required by this module
24+
CLRVersion = '4.0'
25+
26+
# Functions to export from this module
27+
FunctionsToExport = '*'
28+
29+
# Cmdlets to export from this module
30+
CmdletsToExport = '*'
31+
}

0 commit comments

Comments
 (0)