-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Horacio Fernandez
committed
Jul 29, 2014
1 parent
8442949
commit 6d5fab1
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = '*' | ||
} |