Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/linters/PSScriptAnalyzerSettings.psd1
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'
)
}
47 changes: 47 additions & 0 deletions .github/workflows/lint-powershell.yml

Copy link
Copy Markdown
Contributor Author

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.

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."
2 changes: 0 additions & 2 deletions src/dependencies/local-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ if ($Removals) {
$runtimeInformation = [System.Runtime.InteropServices.RuntimeInformation]
$osPlatform = [System.Runtime.InteropServices.OSPlatform]
$IsWindowsPlatform = $runtimeInformation::IsOSPlatform($osPlatform::Windows)
$IsLinuxPlatform = $runtimeInformation::IsOSPlatform($osPlatform::Linux)
$IsMacOSPlatform = $runtimeInformation::IsOSPlatform($osPlatform::OSX)
# lazy temp staging so we only touch disk when needed
$rootTempDir = $null
$playbookTempPath = $null
Expand Down
6 changes: 3 additions & 3 deletions src/playbook/Executables/ASSOC.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function Get-Time {
Write-Output $dateTimeHex
}

function Delete-UserChoiceKey {
function Remove-UserChoiceKey {
param (
[Parameter( Position = 0, Mandatory = $True )]
[String]
Expand Down Expand Up @@ -229,7 +229,7 @@ for ($i = 2; $i -lt $args.Length; $i++) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])" -Force | Out-Null
}
If (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])\UserChoice") {
Delete-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])\UserChoice"
Remove-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])\UserChoice"
}
If (-NOT (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts")) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" -Force | Out-Null
Expand All @@ -246,7 +246,7 @@ for ($i = 2; $i -lt $args.Length; $i++) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])" -Force | Out-Null
}
If (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])\UserChoice") {
Delete-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])\UserChoice"
Remove-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])\UserChoice"
}
If (-NOT (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts")) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" -Force | Out-Null
Expand Down
6 changes: 3 additions & 3 deletions src/playbook/Executables/AtlasModules/Scripts/ASSOC.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function Get-Time {
Write-Output $dateTimeHex
}

function Delete-UserChoiceKey {
function Remove-UserChoiceKey {
param (
[Parameter( Position = 0, Mandatory = $True )]
[String]
Expand Down Expand Up @@ -229,7 +229,7 @@ for ($i = 2; $i -lt $args.Length; $i++) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])" -Force | Out-Null
}
If (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])\UserChoice") {
Delete-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])\UserChoice"
Remove-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\$($splitArg[1])\UserChoice"
}
If (-NOT (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts")) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" -Force | Out-Null
Expand All @@ -246,7 +246,7 @@ for ($i = 2; $i -lt $args.Length; $i++) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])" -Force | Out-Null
}
If (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])\UserChoice") {
Delete-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])\UserChoice"
Remove-UserChoiceKey "$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$($splitArg[0])\UserChoice"
}
If (-NOT (Test-Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts")) {
New-Item -Path "HKU:\$Hive\SOFTWARE\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" -Force | Out-Null
Expand Down
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 @()
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Optimizes NTFS for performance
function Optimize-NTFS {
# Stop tracking last-access timestamps on files; reduces unnecessary disk writes
fsutil behavior set disablelastaccess 1
# Disable 8.3 short filename generation; speeds up directory operations on large folders
fsutil behavior set disable8dot3 1
}

Expand All @@ -11,46 +13,46 @@ function Disable-AutoFolderDiscovery {

# Disables background apps to reduce resource usage
function Disable-BackgroundApps {
$key1 = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications"
reg add $key1 /v "GlobalUserDisabled" /t REG_DWORD /d 1 /f
# Prevents all UWP apps from running in the background globally for this user
$key1 = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications'
$null = New-Item -Path $key1 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $key1 -Name 'GlobalUserDisabled' -Value 1 -Type DWord -Force

$key2 = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search"
reg add $key2 /v "BackgroundAppGlobalToggle" /t REG_DWORD /d 0 /f
# Stops the Windows Search indexer from running background tasks
$key2 = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search'
$null = New-Item -Path $key2 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $key2 -Name 'BackgroundAppGlobalToggle' -Value 0 -Type DWord -Force
}

# Disables Xbox Game Bar and related settings
function Disable-GameBar {
$keys = @(
"HKCU\System\GameConfigStore",
"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR",
"HKCU\SOFTWARE\Microsoft\GameBar",
"HKLM\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId\Windows.Gaming.GameBar.PresenceServer.Internal.PresenceWriter",
"HKLM\SOFTWARE\Policies\Microsoft\Windows\GameDVR",
"HKLM\SOFTWARE\Microsoft\PolicyManager\default\ApplicationManagement\AllowGameDVR"
)

$values = @(
@{ Key = $keys[0]; Name = "GameDVR_Enabled"; Data = 0 },
@{ Key = $keys[1]; Name = "AppCaptureEnabled"; Data = 0 },
@{ Key = $keys[2]; Name = "GamePanelStartupTipIndex"; Data = 3 },
@{ Key = $keys[2]; Name = "ShowStartupPanel"; Data = 0 },
@{ Key = $keys[2]; Name = "UseNexusForGameBarEnabled"; Data = 0 },
@{ Key = $keys[3]; Name = "ActivationType"; Data = 0 },
@{ Key = $keys[4]; Name = "AllowGameDVR"; Data = 0 },
@{ Key = $keys[5]; Name = "value"; Data = 0 }
# New-Item -Force is required before Set-ItemProperty; it silently succeeds if the key already exists
$entries = @(
@{ Path = 'HKCU:\System\GameConfigStore'; Name = 'GameDVR_Enabled'; Value = 0 },
@{ Path = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR'; Name = 'AppCaptureEnabled'; Value = 0 },
@{ Path = 'HKCU:\SOFTWARE\Microsoft\GameBar'; Name = 'GamePanelStartupTipIndex'; Value = 3 },
@{ Path = 'HKCU:\SOFTWARE\Microsoft\GameBar'; Name = 'ShowStartupPanel'; Value = 0 },
@{ Path = 'HKCU:\SOFTWARE\Microsoft\GameBar'; Name = 'UseNexusForGameBarEnabled'; Value = 0 },
@{ Path = 'HKLM:\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId\Windows.Gaming.GameBar.PresenceServer.Internal.PresenceWriter'; Name = 'ActivationType'; Value = 0 },
@{ Path = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\GameDVR'; Name = 'AllowGameDVR'; Value = 0 },
@{ Path = 'HKLM:\SOFTWARE\Microsoft\PolicyManager\default\ApplicationManagement\AllowGameDVR'; Name = 'value'; Value = 0 }
)

foreach ($entry in $values) {
reg add $entry.Key /v $entry.Name /t REG_DWORD /d $entry.Data /f
foreach ($entry in $entries) {
$null = New-Item -Path $entry.Path -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $entry.Path -Name $entry.Name -Value $entry.Value -Type DWord -Force
}
}

# Disables Modern Standby's SleepStudy feature
function Disable-SleepStudy {
Start-Process -FilePath "wevtutil.exe" -ArgumentList 'set-log "Microsoft-Windows-SleepStudy/Diagnostic" /e:false' -NoNewWindow -Wait
Start-Process -FilePath "wevtutil.exe" -ArgumentList 'set-log "Microsoft-Windows-Kernel-Processor-Power/Diagnostic" /e:false' -NoNewWindow -Wait
Start-Process -FilePath "wevtutil.exe" -ArgumentList 'set-log "Microsoft-Windows-UserModePowerService/Diagnostic" /e:false' -NoNewWindow -Wait
schtasks /Change /TN "\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem" /Disable
# wevtutil must be called via Start-Process because it does not have a PowerShell equivalent
# These three event logs are used by SleepStudy to track power activity; disabling them stops the logging
Start-Process -FilePath 'wevtutil.exe' -ArgumentList 'set-log "Microsoft-Windows-SleepStudy/Diagnostic" /e:false' -NoNewWindow -Wait
Start-Process -FilePath 'wevtutil.exe' -ArgumentList 'set-log "Microsoft-Windows-Kernel-Processor-Power/Diagnostic" /e:false' -NoNewWindow -Wait
Start-Process -FilePath 'wevtutil.exe' -ArgumentList 'set-log "Microsoft-Windows-UserModePowerService/Diagnostic" /e:false' -NoNewWindow -Wait
# AnalyzeSystem runs on every boot to generate power reports; not useful on a tuned system
Disable-ScheduledTask -TaskPath '\Microsoft\Windows\Power Efficiency Diagnostics\' -TaskName 'AnalyzeSystem' -ErrorAction SilentlyContinue
}

Export-ModuleMember -Function @()
Loading
Loading