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
34 changes: 9 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,19 @@

## 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).
- xComputer:

=======

## 6.5.0.0

- 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 @@ -43,7 +27,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 @@ -2066,35 +2066,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 @@ -165,10 +165,6 @@ try
Test-TargetResource @testParameters | Should -Be $false
}

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 @@ -209,11 +205,6 @@ try
It 'Should return false from the test method' {
Test-TargetResource @testParameters | Should -Be $false
}

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 @@ -1543,11 +1534,6 @@ try
It 'Should return false from the test method' {
Test-TargetResource @testParameters | Should -Be $false
}

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