Skip to content

Commit 23f8cee

Browse files
committed
Fix up after PR comments
2 parents e65f65c + 8a4cca3 commit 23f8cee

4 files changed

Lines changed: 387 additions & 293 deletions

File tree

.markdownlint.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"default": true,
33
"MD029": {
4-
"style": "ordered"
4+
"style": "one"
55
},
6-
"MD013": false,
6+
"MD013": true,
77
"MD024": true,
88
"MD034": true,
99
"no-hard-tabs": true

DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.psm1

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,12 @@ function Get-TargetResource
267267
$RunOnlyIfNetworkAvailable = $false
268268
)
269269

270+
$TaskPath = ConvertTo-NormalizedTaskPath -TaskPath $TaskPath
271+
270272
Write-Verbose -Message ('Retrieving existing task ({0} in {1})' -f $TaskName, $TaskPath)
273+
271274
$task = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue
272-
275+
273276
if ($null -eq $task)
274277
{
275278
Write-Verbose -Message ('No task found. returning empty task {0} with Ensure = "Absent"' -f $Taskname)
@@ -527,8 +530,8 @@ function Get-TargetResource
527530
}
528531

529532
return @{
530-
TaskName = $TaskName
531-
TaskPath = $TaskPath
533+
TaskName = $task.TaskName
534+
TaskPath = $task.TaskPath
532535
StartTime = $startAt
533536
Ensure = 'Present'
534537
Description = $task.Description
@@ -820,6 +823,8 @@ function Set-TargetResource
820823
$RunOnlyIfNetworkAvailable = $false
821824
)
822825

826+
$TaskPath = ConvertTo-NormalizedTaskPath -TaskPath $TaskPath
827+
823828
Write-Verbose -Message ('Entering Set-TargetResource for {0} in {1}' -f $TaskName, $TaskPath)
824829
$currentValues = Get-TargetResource @PSBoundParameters
825830

@@ -974,7 +979,7 @@ function Set-TargetResource
974979
{
975980
if ($RepetitionDuration.TimeOfDay -le $RepeatInterval.TimeOfDay)
976981
{
977-
$exceptionMessage ='Repetition interval is set to {0} but repetition duration is {1}' -f $RepeatInterval.TimeOfDay, $RepetitionDuration.TimeOfDay
982+
$exceptionMessage = 'Repetition interval is set to {0} but repetition duration is {1}' -f $RepeatInterval.TimeOfDay, $RepetitionDuration.TimeOfDay
978983
New-InvalidArgumentException -Message $exceptionMessage -ArgumentName RepetitionDuration
979984
}
980985

@@ -993,11 +998,11 @@ function Set-TargetResource
993998

994999
if ($currentValues.Ensure -eq 'Present')
9951000
{
996-
Write-Verbose -Message ('Removing previous scheduled task' -f $TaskName)
1001+
Write-Verbose -Message ('Removing previous scheduled task {0}' -f $TaskName)
9971002
$null = Unregister-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Confirm:$false
9981003
}
9991004

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

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

@@ -1042,7 +1047,7 @@ function Set-TargetResource
10421047

10431048
if ($Ensure -eq 'Absent')
10441049
{
1045-
Write-Verbose -Message ('Removing scheduled task' -f $TaskName)
1050+
Write-Verbose -Message ('Removing scheduled task {0}' -f $TaskName)
10461051
Unregister-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Confirm:$false
10471052
}
10481053
}
@@ -1297,6 +1302,8 @@ function Test-TargetResource
12971302
[System.Boolean]
12981303
$RunOnlyIfNetworkAvailable = $false
12991304
)
1305+
1306+
$TaskPath = ConvertTo-NormalizedTaskPath -TaskPath $TaskPath
13001307

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

@@ -1315,6 +1322,36 @@ function Test-TargetResource
13151322
return $false
13161323
}
13171324

1325+
$desiredValues = $PSBoundParameters
1326+
$desiredValues.TaskPath = $TaskPath
1327+
13181328
Write-Verbose -Message 'Testing DSC parameter state'
1319-
return Test-DscParameterState -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters
1329+
return Test-DscParameterState -CurrentValues $CurrentValues -DesiredValues $desiredValues
1330+
}
1331+
1332+
<#
1333+
.SYNOPSIS
1334+
Helper function to convert TaskPath to the right form
1335+
1336+
.PARAMETER TaskPath
1337+
The path to the task
1338+
#>
1339+
1340+
function ConvertTo-NormalizedTaskPath
1341+
{
1342+
[CmdletBinding()]
1343+
param
1344+
(
1345+
[Parameter(Mandatory = $true)]
1346+
[System.String]
1347+
$TaskPath
1348+
)
1349+
1350+
$pathArray = $TaskPath.Split('\').Where( {$_})
1351+
if ($pathArray.Count -gt 0)
1352+
{
1353+
$TaskPath = "\$($pathArray -join '\')\"
1354+
}
1355+
1356+
return $TaskPath
13201357
}

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# xComputerManagement
22

3-
| Branch | Build Status | Code Coverage |
4-
| --- | --- | --- |
5-
| 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) |
6-
| 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) |
7-
83
The **xComputerManagement** module contains the following resources:
94

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

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

21+
## Branches
22+
23+
### master
24+
25+
[![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xsqlserver/branch/master)
26+
[![codecov](https://codecov.io/gh/PowerShell/xComputerManagement/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xComputerManagement/branch/master)
27+
28+
This is the branch containing the latest release - no contributions should be made
29+
directly to this branch.
30+
31+
### dev
32+
33+
[![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/xComputerManagement/branch/dev)
34+
[![codecov](https://codecov.io/gh/PowerShell/xComputerManagement/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/xComputerManagement/branch/dev)
35+
36+
This is the development branch to which contributions should be proposed by contributors
37+
as pull requests. This development branch will periodically be merged to the master
38+
branch, and be released to [PowerShell Gallery](https://www.powershellgallery.com/).
39+
2440
## Contributing
2541

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

161178
### Unreleased
162179

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

169188
### 2.0.0.0
170189

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

176195
### 1.10.0.0
177196

178-
* Added resources
197+
* Added resources:
179198
* xVirtualMemory
180199

181200
### 1.9.0.0

0 commit comments

Comments
 (0)