LeDragoX / Win-Debloat-Tools

Re-imagining Windows like a minimal OS install, already debloated with minimal impact for most functionality.
MIT License
4.82k stars 245 forks source link

Issue with Loading PSScheduledJob Module in PowerShell Script #119

Closed us254 closed 8 months ago

us254 commented 9 months ago

Describe the Bug

I encountered an issue in a PowerShell script where the PSScheduledJob module is not being loaded correctly, resulting in errors when trying to use cmdlets from this module. Specifically, the New-JobTrigger and Get-ScheduledJob cmdlets are affected.

the lines of code causing the problem and the modifications needed to fix it are as follows:

  1. Line 47:
Trigger = New-JobTrigger -Daily -At $Time

To fix this line, you should add Import-Module PSScheduledJob before using the New-JobTrigger cmdlet, like this:

Import-Module PSScheduledJob
Trigger = New-JobTrigger -Daily -At $Time
  1. Line 51:
(Get-ScheduledJob -Name $JobName -ErrorAction SilentlyContinue) -or (Get-ScheduledJob -Name $ ...

To fix this line, you should also add Import-Module PSScheduledJob before using the Get-ScheduledJob cmdlet, like this:

Import-Module PSScheduledJob
(Get-ScheduledJob -Name $JobName -ErrorAction SilentlyContinue) -or (Get-ScheduledJob -Name $ ...

How can this issue be reproduced?

To reproduce the issue, you can follow these steps:

1: Run the PowerShell script (Install-PackageManager.ps1) that attempts to create a daily task to automatically upgrade Chocolatey packages at 13:00. 2: Observe the error messages related to the PSScheduledJob module not being loaded.

Expected behavior?

When running the PowerShell script, I expected the PSScheduledJob module to be loaded successfully, allowing the script to create a scheduled task and manage scheduled jobs without encountering any errors.

Operating System

Windows 11

Operating System Version

10.0.22621 N/A Build 22621

Screenshots

No response

Logs

No response

Additional Info

No response