Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScheduledTask: Removing helper function Disable-ScheduledTask #228

Closed
wants to merge 19 commits into from
Closed
30 changes: 5 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- ScheduledTask:
- Removed Disable-ScheduledTask helper function as it does not work with most
of the built-in scheduled tasks. Removing the function means that built-in
one is used instead which works as expected - Fixes [Issue #137](https://github.com/PowerShell/ComputerManagementDsc/issues/137).
- Changes to ScheduledTask:
- Delay property not handled properly on AtLogon and AtStartup trigger - Fixes
[Issue #230](https://github.com/PowerShell/ComputerManagementDsc/issues/230)
Expand Down Expand Up @@ -42,30 +46,6 @@
- Computer:
- Fix for 'directory service is busy' error when joining a domain and renaming
a computer when JoinOU is specified - Fixes [Issue #221](https://github.com/PowerShell/ComputerManagementDsc/issues/221).
- Added new resource SmbShare
- Moved and improved from deprecated module xSmbShare.
- Changes to ComputerManagementDsc.Common
- Updated Test-DscParameterState so it now can compare zero item
collections (arrays).
- Changes to WindowsEventLog
- Minor style guideline cleanup.
- Opt-in to common test to validate localization. Fixed localization strings
in resources - Fixes [Issue #217](https://github.com/PowerShell/ComputerManagementDsc/issues/217).
- PowerShellExecutionPolicy:
- Removed `SupportsShouldProcess` as it cannot be used with DSC - Fixes
[Issue #219](https://github.com/PowerShell/ComputerManagementDsc/issues/219).
- Combined all ComputerManagementDsc.ResourceHelper module functions into
ComputerManagementDsc.Common module - Fixes [Issue #218](https://github.com/PowerShell/ComputerManagementDsc/issues/218).
- Minor code cleanup against style guideline.
- Remove code from `New-InvalidOperationException` because it was a
code path that could never could be used due to the parameter
validation preventing the helper function being called that way.
- Updated all `Get-LocalizationData` to latest version from
[DSCResource.Template](https://github.com/PowerShell/DSCResource.Template).
- Fixed an issue with the helper function `Test-IsNanoServer` that
prevented it to work. Though the helper function is not used, so this
issue was not caught until now when unit tests was added.
- Improved code coverage.

## 6.4.0.0

Expand All @@ -78,7 +58,7 @@
- Added a CODE\_OF\_CONDUCT.md with the same content as in the README.md and
linked to it from README.MD instead.
- Updated test header for all unit tests to version 1.2.4.
- Updated test header for all integration to version 1.3.3.
- Updated test header for all imtegration to version 1.3.3.
- Enabled example publish to PowerShell Gallery by adding `gallery_api`
environment variable to `AppVeyor.yml`.

Expand Down
29 changes: 0 additions & 29 deletions DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1586,35 +1586,6 @@ function ConvertTo-TimeSpanStringFromScheduledTaskString
return (New-TimeSpan -Days $days -Hours $hours -Minutes $minutes -Seconds $seconds).ToString()
}

<#
.SYNOPSIS
Helper function to disable an existing scheduled task.

.PARAMETER TaskName
The name of the task to disable.

.PARAMETER TaskPath
The path to the task to disable.
#>
function Disable-ScheduledTask
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$TaskName,

[Parameter()]
[System.String]
$TaskPath = '\'
)

$existingTask = Get-ScheduledTask @PSBoundParameters
$existingTask.Settings.Enabled = $false
$null = $existingTask | Register-ScheduledTask @PSBoundParameters -Force
}

<#
.SYNOPSIS
Returns a formatted datetime string for use in ScheduledTask resource.
Expand Down
14 changes: 0 additions & 14 deletions Tests/Unit/MSFT_ScheduledTask.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ try
Test-TargetResource @testParameters | Should -BeFalse
}

It 'Should remove the scheduled task in the set method' {
Set-TargetResource @testParameters
Assert-MockCalled Unregister-ScheduledTask
}
}

Context 'A built-in scheduled task exists and is enabled, but it should be disabled' {
Expand Down Expand Up @@ -208,11 +204,6 @@ try
It 'Should return false from the test method' {
Test-TargetResource @testParameters | Should -BeFalse
}

It 'Should remove the scheduled task in the set method' {
Set-TargetResource @testParameters
Assert-MockCalled Register-ScheduledTask -Exactly -Times 1
}
}

Context 'A built-in scheduled task exists, but it should be absent' {
Expand Down Expand Up @@ -1492,11 +1483,6 @@ try
It 'Should return false from the test method' {
Test-TargetResource @testParameters | Should -BeFalse
}

It 'Should disable the scheduled task in the set method' {
Set-TargetResource @testParameters
Assert-MockCalled Register-ScheduledTask -Exactly -Times 1
}
}

Context 'When a scheduled task with an OnEvent scheduletype is in desired state' {
Expand Down