-
-
Notifications
You must be signed in to change notification settings - Fork 747
refactor: replace deprecated reg/sc/wmic/setx/schtasks with PowerShell cmdlets #1648
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
67408ca
refactor: replace deprecated reg/sc/wmic/setx/schtasks with PowerShel…
Stensel8 6c5372d
ci: add PSScriptAnalyzer lint workflow
Stensel8 fd65d69
ci: pin actions/checkout to v6.0.2
Stensel8 5ceeb41
fix: resolve PSScriptAnalyzer warnings (rename Delete- verb, fix empt…
Stensel8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| @{ | ||
| Severity = @('Error', 'Warning') | ||
|
|
||
| ExcludeRules = @( | ||
| # Atlas scripts use Write-Host intentionally for colored playbook output | ||
| 'PSAvoidUsingWriteHost', | ||
| # Positional parameters are common in short Atlas helper calls | ||
| 'PSAvoidUsingPositionalParameters', | ||
| # Internal Atlas scripts are not published cmdlets; ShouldProcess is not applicable | ||
| 'PSUseShouldProcessForStateChangingFunctions', | ||
| # Internal function names do not need to follow module-publishing conventions | ||
| 'PSUseSingularNouns', | ||
| # InstallSoftware.ps1 uses global vars intentionally for its progress display state machine | ||
| 'PSAvoidGlobalVars', | ||
| # BOM handling is a per-file encoding decision, not enforced project-wide | ||
| 'PSUseBOMForUnicodeEncodedFile', | ||
| # Script-level params used inside nested functions trigger a false positive in PSSA | ||
| 'PSReviewUnusedParameter' | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| name: Lint PowerShell | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - "src/**/*.ps1" | ||
| - "src/**/*.psm1" | ||
| - ".github/linters/PSScriptAnalyzerSettings.psd1" | ||
| - ".github/workflows/lint-powershell.yml" | ||
| pull_request: | ||
| paths: | ||
| - "src/**/*.ps1" | ||
| - "src/**/*.psm1" | ||
| - ".github/linters/PSScriptAnalyzerSettings.psd1" | ||
| - ".github/workflows/lint-powershell.yml" | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| psscriptanalyzer: | ||
| runs-on: windows-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| # gh api repos/actions/checkout/commits/v6.0.2 --jq '.sha' | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Install PSScriptAnalyzer | ||
| shell: pwsh | ||
| run: | | ||
| # Pin to a specific version so results are reproducible | ||
| # Update RequiredVersion when a new release ships on PowerShell Gallery | ||
| Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Force -Scope CurrentUser | ||
|
|
||
| - name: Run PSScriptAnalyzer | ||
| shell: pwsh | ||
| run: | | ||
| $settings = '.github/linters/PSScriptAnalyzerSettings.psd1' | ||
| $results = Get-ChildItem -Path 'src' -Recurse -Include '*.ps1','*.psm1' | | ||
| Invoke-ScriptAnalyzer -Settings $settings | ||
|
|
||
| if ($results) { | ||
| $results | Format-Table -AutoSize | ||
| Write-Host "::error::PSScriptAnalyzer found $($results.Count) issue(s)." | ||
| exit 1 | ||
| } | ||
|
|
||
| Write-Host "No issues found." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 52 additions & 44 deletions
96
src/playbook/Executables/AtlasModules/Scripts/Modules/Debloat/Debloat.psm1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,74 @@ | ||
| function Set-ContentDelivery{ | ||
| function Set-ContentDelivery { | ||
| Write-Host "Setting Content Delivery" | ||
| $key = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; | ||
| $data = "0" | ||
| # ContentDeliveryManager controls Windows suggestions, sponsored apps, and lock screen ads. | ||
| # Setting all these values to 0 stops Windows from silently installing apps and showing promotions. | ||
| $key = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' | ||
| $data = 0 | ||
| $values = @( | ||
| "ContentDeliveryAllowed", | ||
| "FeatureManagementEnabled", | ||
| "SubscribedContentEnabled", | ||
| "RemediationRequired", | ||
| "OemPreInstalledAppsEnabled", | ||
| "PreInstalledAppsEnabled", | ||
| "PreInstalledAppsEverEnabled", | ||
| "SilentInstalledAppsEnabled", | ||
| "EnableAccountNotifications", | ||
| "SubscribedContent-310093Enabled", | ||
| "SubscribedContent-338393Enabled", | ||
| "SubscribedContent-353694Enabled", | ||
| "SubscribedContent-353696Enabled", | ||
| "SubscribedContent-338388Enabled", | ||
| "SubscribedContent-338387Enabled", | ||
| "SubscribedContent-338389Enabled", | ||
| "SystemPaneSuggestionsEnabled", | ||
| "RotatingLockScreenOverlayEnabled", | ||
| "SoftLandingEnabled" | ||
| 'ContentDeliveryAllowed', | ||
| 'FeatureManagementEnabled', | ||
| 'SubscribedContentEnabled', | ||
| 'RemediationRequired', | ||
| 'OemPreInstalledAppsEnabled', | ||
| 'PreInstalledAppsEnabled', | ||
| 'PreInstalledAppsEverEnabled', | ||
| 'SilentInstalledAppsEnabled', | ||
| 'EnableAccountNotifications', | ||
| 'SubscribedContent-310093Enabled', | ||
| 'SubscribedContent-338393Enabled', | ||
| 'SubscribedContent-353694Enabled', | ||
| 'SubscribedContent-353696Enabled', | ||
| 'SubscribedContent-338388Enabled', | ||
| 'SubscribedContent-338387Enabled', | ||
| 'SubscribedContent-338389Enabled', | ||
| 'SystemPaneSuggestionsEnabled', | ||
| 'RotatingLockScreenOverlayEnabled', | ||
| 'SoftLandingEnabled' | ||
| ) | ||
|
|
||
| foreach ($value in $values){ | ||
| reg add $key /v $value /t REG_DWORD /d $data /f > $null | ||
| $null = New-Item -Path $key -Force -ErrorAction SilentlyContinue | ||
| foreach ($value in $values) { | ||
| Set-ItemProperty -Path $key -Name $value -Value $data -Type DWord -Force | ||
| } | ||
| reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\SystemSettings\AccountNotifications" /t REG_DWORD /v 'EnableAccountNotifications' /d "0" /f > $null | ||
|
|
||
| # This separate key controls account-related notifications in the Settings app | ||
| $path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\SystemSettings\AccountNotifications' | ||
| $null = New-Item -Path $path -Force -ErrorAction SilentlyContinue | ||
| Set-ItemProperty -Path $path -Name 'EnableAccountNotifications' -Value 0 -Type DWord -Force | ||
| } | ||
|
|
||
| function Set-StorageSense{ | ||
| function Set-StorageSense { | ||
| Write-Host "Setting Storage Sense" | ||
| $key = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy" | ||
| $values = @( | ||
| "32", | ||
| "02", | ||
| "128", | ||
| "08", | ||
| "256" | ||
| ) | ||
| # StorageSense uses numeric value names as identifiers for each cleanup policy option. | ||
| # Values set to 0 are disabled; values set to 1 or higher control cleanup intervals. | ||
| $key = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy' | ||
| $null = New-Item -Path $key -Force -ErrorAction SilentlyContinue | ||
|
|
||
| foreach ($value in $values){ | ||
| reg add $key /t REG_DWORD /v $value /d "0" /f | ||
| # Disable cleanup for: downloads (32), recycle bin (02), temp files (128), offline files (08), previous versions (256) | ||
| foreach ($value in @('32', '02', '128', '08', '256')) { | ||
| Set-ItemProperty -Path $key -Name $value -Value 0 -Type DWord -Force | ||
| } | ||
| reg add $key /t REG_DWORD /v '01' /d "1" /f | ||
| reg add $key /t REG_DWORD /v '1024' /d "1" /f | ||
| reg add $key /t REG_DWORD /v '04' /d "1" /f | ||
| reg add $key /t REG_DWORD /v '2048' /d "30" /f | ||
| Start-ScheduledTask -TaskPath "\Microsoft\Windows\DiskCleanup" -TaskName "SilentCleanup" | ||
| Set-ItemProperty -Path $key -Name '01' -Value 1 -Type DWord -Force # Enable Storage Sense itself | ||
| Set-ItemProperty -Path $key -Name '1024' -Value 1 -Type DWord -Force # Run when low on disk space | ||
| Set-ItemProperty -Path $key -Name '04' -Value 1 -Type DWord -Force # Delete temp files | ||
| Set-ItemProperty -Path $key -Name '2048' -Value 30 -Type DWord -Force # Keep files in recycle bin for 30 days | ||
| # Run the cleanup task immediately so settings take effect without waiting for the next scheduled run | ||
| Start-ScheduledTask -TaskPath '\Microsoft\Windows\DiskCleanup' -TaskName 'SilentCleanup' | ||
| } | ||
|
|
||
| function Set-DisableStorageSense { | ||
| Write-Host "Disabling Storage Sense" | ||
| # Reserved storage is disk space Windows sets aside for updates; freeing it saves space on small drives | ||
| dism.exe /Online /Set-ReservedStorageState /State:Disabled | ||
| } | ||
|
|
||
| function Set-DisabledScheduledTasks { | ||
| Write-Host "Disabling ScheduledTasks" | ||
| Disable-ScheduledTask -TaskPath "\Microsoft\Windows\Application Experience\" -TaskName "PcaPatchDbTask" | ||
| Disable-ScheduledTask -TaskPath "\Microsoft\Windows\AppxDeploymentClient\" -TaskName "UCPD velocity" -ErrorAction SilentlyContinue | ||
| Disable-ScheduledTask -TaskPath "\Microsoft\Windows\Flighting\FeatureConfig\" -TaskName "UsageDataReporting" -ErrorAction SilentlyContinue | ||
| # PcaPatchDbTask runs program compatibility scans after app installs; not needed on a clean system | ||
| Disable-ScheduledTask -TaskPath '\Microsoft\Windows\Application Experience\' -TaskName 'PcaPatchDbTask' | ||
| # UCPD velocity and UsageDataReporting send usage telemetry to Microsoft | ||
| Disable-ScheduledTask -TaskPath '\Microsoft\Windows\AppxDeploymentClient\' -TaskName 'UCPD velocity' -ErrorAction SilentlyContinue | ||
| Disable-ScheduledTask -TaskPath '\Microsoft\Windows\Flighting\FeatureConfig\' -TaskName 'UsageDataReporting' -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| Export-ModuleMember -Function @() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a preconfigured action for this, but this one seems unmaintained so I'm not sure.
https://github.com/marketplace/actions/run-psscriptanalyzer
The current method with the actions/checkout works fine though. It lints files correctly when ran on my fork.