Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Horacio Fernandez committed Jul 29, 2014
1 parent 8442949 commit 6d5fab1
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
76 changes: 76 additions & 0 deletions DSCResources/RS_rsScheduledTask/RS_rsScheduledTask.psm1
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.
31 changes: 31 additions & 0 deletions rsScheduledTask.psd1
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 = '*'
}

0 comments on commit 6d5fab1

Please sign in to comment.