Skip to content

Commit

Permalink
Fix up after PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO committed Jul 17, 2017
2 parents e65f65c + 8a4cca3 commit 23f8cee
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 293 deletions.
4 changes: 2 additions & 2 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"default": true,
"MD029": {
"style": "ordered"
"style": "one"
},
"MD013": false,
"MD013": true,
"MD024": true,
"MD034": true,
"no-hard-tabs": true
Expand Down
53 changes: 45 additions & 8 deletions DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,12 @@ function Get-TargetResource
$RunOnlyIfNetworkAvailable = $false
)

$TaskPath = ConvertTo-NormalizedTaskPath -TaskPath $TaskPath

Write-Verbose -Message ('Retrieving existing task ({0} in {1})' -f $TaskName, $TaskPath)

$task = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue

if ($null -eq $task)
{
Write-Verbose -Message ('No task found. returning empty task {0} with Ensure = "Absent"' -f $Taskname)
Expand Down Expand Up @@ -527,8 +530,8 @@ function Get-TargetResource
}

return @{
TaskName = $TaskName
TaskPath = $TaskPath
TaskName = $task.TaskName
TaskPath = $task.TaskPath
StartTime = $startAt
Ensure = 'Present'
Description = $task.Description
Expand Down Expand Up @@ -820,6 +823,8 @@ function Set-TargetResource
$RunOnlyIfNetworkAvailable = $false
)

$TaskPath = ConvertTo-NormalizedTaskPath -TaskPath $TaskPath

Write-Verbose -Message ('Entering Set-TargetResource for {0} in {1}' -f $TaskName, $TaskPath)
$currentValues = Get-TargetResource @PSBoundParameters

Expand Down Expand Up @@ -974,7 +979,7 @@ function Set-TargetResource
{
if ($RepetitionDuration.TimeOfDay -le $RepeatInterval.TimeOfDay)
{
$exceptionMessage ='Repetition interval is set to {0} but repetition duration is {1}' -f $RepeatInterval.TimeOfDay, $RepetitionDuration.TimeOfDay
$exceptionMessage = 'Repetition interval is set to {0} but repetition duration is {1}' -f $RepeatInterval.TimeOfDay, $RepetitionDuration.TimeOfDay
New-InvalidArgumentException -Message $exceptionMessage -ArgumentName RepetitionDuration
}

Expand All @@ -993,11 +998,11 @@ function Set-TargetResource

if ($currentValues.Ensure -eq 'Present')
{
Write-Verbose -Message ('Removing previous scheduled task' -f $TaskName)
Write-Verbose -Message ('Removing previous scheduled task {0}' -f $TaskName)
$null = Unregister-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Confirm:$false
}

Write-Verbose -Message ('Creating new scheduled task' -f $TaskName)
Write-Verbose -Message ('Creating new scheduled task {0}' -f $TaskName)

$scheduledTask = New-ScheduledTask -Action $action -Trigger $trigger -Settings $setting

Expand Down Expand Up @@ -1042,7 +1047,7 @@ function Set-TargetResource

if ($Ensure -eq 'Absent')
{
Write-Verbose -Message ('Removing scheduled task' -f $TaskName)
Write-Verbose -Message ('Removing scheduled task {0}' -f $TaskName)
Unregister-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Confirm:$false
}
}
Expand Down Expand Up @@ -1297,6 +1302,8 @@ function Test-TargetResource
[System.Boolean]
$RunOnlyIfNetworkAvailable = $false
)

$TaskPath = ConvertTo-NormalizedTaskPath -TaskPath $TaskPath

Write-Verbose -Message ('Testing scheduled task {0}' -f $TaskName)

Expand All @@ -1315,6 +1322,36 @@ function Test-TargetResource
return $false
}

$desiredValues = $PSBoundParameters
$desiredValues.TaskPath = $TaskPath

Write-Verbose -Message 'Testing DSC parameter state'
return Test-DscParameterState -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters
return Test-DscParameterState -CurrentValues $CurrentValues -DesiredValues $desiredValues
}

<#
.SYNOPSIS
Helper function to convert TaskPath to the right form
.PARAMETER TaskPath
The path to the task
#>

function ConvertTo-NormalizedTaskPath
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$TaskPath
)

$pathArray = $TaskPath.Split('\').Where( {$_})
if ($pathArray.Count -gt 0)
{
$TaskPath = "\$($pathArray -join '\')\"
}

return $TaskPath
}
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# xComputerManagement

| Branch | Build Status | Code Coverage |
| --- | --- | --- |
| master | [![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xComputerManagement/branch/master) | [![codecov](https://codecov.io/gh/PowerShell/xComputerManagement/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xComputerManagement/branch/master) |
| dev | [![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/xComputerManagement/branch/dev) | [![codecov](https://codecov.io/gh/PowerShell/xComputerManagement/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/xComputerManagement/branch/dev) |

The **xComputerManagement** module contains the following resources:

* xComputer - allows you to configure a computer by changing its name and
Expand All @@ -15,12 +10,33 @@ The **xComputerManagement** module contains the following resources:
* xScheduledTask - used to define basic recurring scheduled tasks on the
local computer.
* xPowerPlan - specifies a power plan to activate.
* xVirtualMemory - used to set the properties of the paging file on the
local computer.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any
additional questions or comments.

## Branches

### master

[![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xsqlserver/branch/master)
[![codecov](https://codecov.io/gh/PowerShell/xComputerManagement/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xComputerManagement/branch/master)

This is the branch containing the latest release - no contributions should be made
directly to this branch.

### dev

[![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/xComputerManagement/branch/dev)
[![codecov](https://codecov.io/gh/PowerShell/xComputerManagement/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/xComputerManagement/branch/dev)

This is the development branch to which contributions should be proposed by contributors
as pull requests. This development branch will periodically be merged to the master
branch, and be released to [PowerShell Gallery](https://www.powershellgallery.com/).

## Contributing

Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md).
Expand Down Expand Up @@ -65,7 +81,8 @@ xScheduledTask has the following properties:
task?
* StartTime: The time of day this task should start at - defaults to 12:00 AM.
Not valid for AtLogon and AtStartup tasks
* Ensure: Present if the task should exist, false if it should be removed
* Ensure: Present if the task should exist, false if it should be removed - defaults
to Present.
* Enable: True if the task should be enabled, false if it should be
disabled
* ExecuteAsCredential: The credential this task should execute as. If not
Expand Down Expand Up @@ -160,11 +177,13 @@ xVirtualMemory has the following properties:

### Unreleased

* xComputer: Changed comparision that validates if we are in the correct AD
Domain to work correctly if FQDN wasn't used
* xComputer: Changed comparison that validates if we are in the correct AD
Domain to work correctly if FQDN wasn't used.
* Updated AppVeyor.yml to use AppVeyor.psm1 module in DSCResource.Tests.
* Removed Markdown.md errors.
* Added CodeCov.io support.
* xScheduledTask
* Fixed incorrect TaskPath handling - [Issue #45](https://github.com/PowerShell/xComputerManagement/issues/45)

### 2.0.0.0

Expand All @@ -175,7 +194,7 @@ xVirtualMemory has the following properties:

### 1.10.0.0

* Added resources
* Added resources:
* xVirtualMemory

### 1.9.0.0
Expand Down
Loading

0 comments on commit 23f8cee

Please sign in to comment.