Skip to content

Commit 660b5fe

Browse files
committed
June 2024 update (see the change log for details)
1 parent 9980e0a commit 660b5fe

29 files changed

+451
-68
lines changed
File renamed without changes.

Maintenance/Get installed apps.ps1 renamed to Apps/Get installed apps.ps1

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Queries Windows Registry for a list of installed apps
44
.DESCRIPTION
55
Queries Windows Registry for a list of apps that have registered uninstallers. Displays their
6-
technical moniker, friendly name, and their registered uninstaller.
6+
technical Arch, friendly name, and their registered uninstaller.
77
.EXAMPLE
88
PS C:\> Get installed apps.ps1
99
@@ -55,38 +55,74 @@ using namespace System.Management.Automation
5555
[CmdletBinding()]
5656
param()
5757

58-
function PublicStaticVoidMain {
59-
# No [CmdletBinding()] or param() allowed here!
60-
# Define parameter is in the main param() block above.
58+
function GetInstallAppsFragment {
59+
[CmdletBinding()]
60+
param (
61+
[Parameter(Mandatory,Position=0)]
62+
[string]
63+
$Arch,
6164

62-
$QParams = @{
63-
Path = @(
64-
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
65-
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
66-
)
67-
Exclude = @(
68-
'SchedulingAgent',
69-
'MobileOptionPack',
70-
'WIC',
71-
'AddressBook',
72-
'Connection Manager',
73-
'DirectDrawEx',
74-
'IEData',
75-
'IE5BAKEX',
76-
'Fontcore',
77-
'IE4Data',
78-
'IE40',
79-
'7-Zip'
80-
)
81-
}
82-
$a = Get-ChildItem @QParams -ErrorAction 'Stop'
65+
[Parameter(Mandatory,Position=1)]
66+
[string[]]
67+
$GetChildItemLiteralPath,
8368

84-
$a | Select-Object -Property @(
69+
[Parameter(Mandatory,Position=2)]
70+
[string[]]
71+
$GetChildItemExclude
72+
)
73+
74+
$gci = Get-ChildItem -LiteralPath $GetChildItemLiteralPath -Exclude $GetChildItemExclude -ErrorAction 'SilentlyContinue'
75+
return $gci | Select-Object -Property @(
76+
@{n = "Arch"; e = { $Arch } }
8577
@{n = "Scope"; e = { $_.PSDrive.Name } }
8678
@{n = "Name"; e = { $_.PSChildName } }
8779
@{n = "Display name"; e = { $_.GetValue("DisplayName") } }
8880
@{n = "Uninstall string"; e = { $_.GetValue("UninstallString") } }
89-
) | Sort-Object -Property "Scope", "Display name"
81+
)
82+
9083
}
9184

92-
PublicStaticVoidMain @args
85+
$x64QueryParameters = @{
86+
Arch = "x64"
87+
GetChildItemLiteralPath = @(
88+
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
89+
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
90+
)
91+
GetChildItemExclude = @(
92+
'7-Zip'
93+
'AddressBook'
94+
'Connection Manager'
95+
'DirectDrawEx'
96+
'Fontcore'
97+
'IE40'
98+
'IE4Data'
99+
'IE5BAKEX'
100+
'IEData'
101+
'MobileOptionPack'
102+
'SchedulingAgent'
103+
'WIC'
104+
)
105+
}
106+
GetInstallAppsFragment @x64QueryParameters
107+
108+
$IA32QueryParameters = @{
109+
Arch = "IA-32"
110+
GetChildItemLiteralPath = @(
111+
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
112+
'HKCU:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
113+
)
114+
GetChildItemExclude = @(
115+
'AddressBook'
116+
'Connection Manager'
117+
'DirectDrawEx'
118+
'Fontcore'
119+
'IE40'
120+
'IE4Data'
121+
'IE5BAKEX'
122+
'IEData'
123+
'MobileOptionPack'
124+
'SchedulingAgent'
125+
'WIC'
126+
)
127+
}
128+
GetInstallAppsFragment @IA32QueryParameters

Apps/Is x64.ps1

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<#
2+
.SYNOPSIS
3+
Determines whether an EXE file is marked as x64.
4+
.DESCRIPTION
5+
Determines whether an EXE file is marked as x64.
6+
.EXAMPLE
7+
PS C:\> & "Is x64.ps1" -LiteralPath C:\Windows\Notepad.exe
8+
True
9+
.INPUTS
10+
None
11+
.OUTPUTS
12+
Boolean
13+
.NOTES
14+
None
15+
#>
16+
17+
#Requires -Version 5.1
18+
19+
using namespace System.Management.Automation
20+
21+
[CmdletBinding()]
22+
param (
23+
<#
24+
Specifies a path to an executable file. Unlike the Path parameter, the value of the LiteralPath
25+
parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path
26+
includes escape characters, enclose it in single quotation marks. Single quotation marks tell
27+
Windows PowerShell not to interpret any characters as escape sequences.
28+
#>
29+
[Parameter(
30+
Mandatory,
31+
Position = 0,
32+
ParameterSetName = "LiteralPath",
33+
ValueFromPipelineByPropertyName,
34+
HelpMessage = "Literal path to an executable file.")]
35+
[Alias("PSPath", "Path")]
36+
[ValidateNotNullOrEmpty()]
37+
[string]
38+
$LiteralPath
39+
)
40+
41+
[UInt16]$MZIdentifier = 0x5A4D # MZ
42+
[UInt16]$PEIdentifier = 0x4550 # PE
43+
[UInt16]$64Identifier = 0x8664
44+
$PeOffset = 60
45+
$MachineOffset = 4
46+
$MemoryStreamSize = 2kB
47+
48+
function MachineUIntToString {
49+
[OutputType([String])]
50+
param (
51+
[UInt16]$InputObject
52+
)
53+
switch ($InputObject) {
54+
0x0000 { return "Unknown machine type" }
55+
0x014c { return "Intel 386 or later family processors" }
56+
0x0166 { return "MIPS little endian" }
57+
0x0169 { return "MIPS little-endian WCE v2" }
58+
0x01a2 { return "Hitachi SH3" }
59+
0x01a3 { return "Hitachi SH3 DSP" }
60+
0x01a6 { return "Hitachi SH4" }
61+
0x01a8 { return "Hitachi SH5" }
62+
0x01c0 { return "ARM little endian" }
63+
0x01c2 { return "ARM or Thumb (`“interworking`”)" }
64+
0x01c4 { return "ARMv7 (or higher) Thumb mode only" }
65+
0x01d3 { return "Matsushita AM33" }
66+
0x01f0 { return "Power PC little endian" }
67+
0x01f1 { return "Power PC with floating point support" }
68+
0x0200 { return "Intel Itanium processor family" }
69+
0x0266 { return "MIPS16" }
70+
0x0366 { return "MIPS with FPU" }
71+
0x0466 { return "MIPS16 with FPU" }
72+
0x0ebc { return "EFI byte code" }
73+
0x8664 { return "x64" }
74+
0x9041 { return "Mitsubishi M32R little endian" }
75+
0xaa64 { return "ARMv8 in 64-bit mode" }
76+
}
77+
}
78+
79+
function TerminateBadEXE {
80+
$PSCmdlet.ThrowTerminatingError(
81+
[ErrorRecord]::new(
82+
[IO.FileFormatException]::new('The specified file is not a valid Windows EXE.'),
83+
'BadFileFormat',
84+
[ErrorCategory]::MetadataError,
85+
$LiteralPath
86+
)
87+
)
88+
}
89+
90+
if (-not (Test-Path -Path $LiteralPath -PathType Leaf)) {
91+
$PSCmdlet.ThrowTerminatingError(
92+
[ErrorRecord]::new(
93+
[IO.FileNotFoundException]::new(),
94+
'ObjectNotFound',
95+
[ErrorCategory]::ObjectNotFound,
96+
$LiteralPath
97+
)
98+
)
99+
}
100+
101+
try {
102+
[Byte[]]$Data = [Byte[]]::new($MemoryStreamSize)
103+
$MyFileStream = [IO.FileStream]::new($LiteralPath, 'Open', 'Read')
104+
$MyFileStream.Read($Data, 0, $MemoryStreamSize) | Out-Null
105+
} catch {
106+
throw
107+
}
108+
finally {
109+
if ($null -ne $MyFileStream) { $MyFileStream.Close() }
110+
}
111+
112+
if ($MZIdentifier -ne [BitConverter]::ToUInt16($Data, 0)) {
113+
TerminateBadEXE
114+
}
115+
116+
$PeHeaderAddress = [BitConverter]::ToInt32($Data, $PeOffset)
117+
if ($PEIdentifier -ne [BitConverter]::ToUInt16($Data, $PeHeaderAddress)) {
118+
TerminateBadEXE
119+
}
120+
121+
$MachineUInt = [BitConverter]::ToUInt16($data, $PeHeaderAddress + $MachineOffset)
122+
Write-Verbose -Message $(MachineUIntToString -InputObject $MachineUInt)
123+
return ($64Identifier -eq $MachineUInt)
File renamed without changes.
File renamed without changes.

Changelog.markdown

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Change log
22

3+
## June 2024
4+
5+
New:
6+
7+
- `Apps\Is x64.ps1`
8+
- `Hardware\Set-BluetoothRadio.ps1`
9+
- `Security\Malicious Software Removal Tool\Allow Windows Update to install MRT.reg`
10+
- `Security\Malicious Software Removal Tool\Prevent Windows Update from installing MRT.reg`
11+
- `Shell\Folder view state\Delete folder view state.reg`
12+
- `Shell\Promotional Store apps (pre-Setup)\Disable promotional Store apps.reg`
13+
- `Shell\Promotional Store apps (pre-Setup)\Enable promotional Store apps.reg`
14+
- `Shell\Removable drives outside This PC\Hide removable drives outside This PC.reg`
15+
- `Shell\Removable drives outside This PC\Show removable drives outside This PC, 32-bit.reg`
16+
- `Shell\Removable drives outside This PC\Show removable drives outside This PC, 64-bit.reg`
17+
- `Shell\Special folders under This PC\Remove all special folders from This PC, 32-bit.reg`
18+
- `Shell\Special folders under This PC\Remove all special folders from This PC, 64-bit.reg`
19+
- `Shell\Special folders under This PC\Restore all special folders to This PC, 32-bit.reg`
20+
- `Shell\Special folders under This PC\Restore all special folders to This PC, 64-bit.reg`
21+
- `Shell\Telemetry\Disable diagnostics data collection (reversible with Settings app).reg`
22+
- `Shell\Web results in Windows Search\Disable web results in Windows Search.reg`
23+
- `Shell\Web results in Windows Search\Restore web results to Windows Search.reg`
24+
25+
Changed:
26+
27+
- **AppX**: Renamed to **Apps**
28+
- **Get installed apps.ps1**: Moved into the `Apps` folder
29+
- **Optimize PATH variable.ps1**: Improved reliability
30+
- **Find redundant drivers.ps1**: Minor wording change
31+
- **Get Windows Firewall status.cmd**: Moved into the `Security\Others` folder
32+
- **Clear Windows Defender history.ps1**: Moved into the `Security\Others` folder
33+
334
## March 2024
435

536
Changed:

Hardware/Set-BluetoothRadio.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[CmdletBinding()]
2+
Param (
3+
[Parameter(Mandatory = $true)]
4+
[ValidateSet('Off', 'On')]
5+
[String]$BluetoothStatus
6+
)
7+
8+
If ($PSVersionTable.PSVersion.Major -ne 5) {
9+
Write-Error -Message "This script only runs on PowerShell 5.x because of limitations that Microsoft has put in place." -ErrorAction 'Stop'
10+
return
11+
}
12+
13+
if ([Environment]::OSVersion.Version.Build -lt 10240) {
14+
Write-Error -Message "This script requires Windows 10 or later, or their Windows Server equivalents." -Exception 'Stop'
15+
}
16+
17+
# The following line is NOT necessary. The Bluetooth service is a trigger-start service and doesn't
18+
# need an explicit start command. Said command need administrative privileges anyway.
19+
#
20+
# If ((Get-Service bthserv).Status -eq 'Stopped') { Start-Service bthserv }
21+
22+
Add-Type -AssemblyName System.Runtime.WindowsRuntime
23+
24+
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
25+
26+
Function Await($WinRtTask, $ResultType) {
27+
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
28+
$netTask = $asTask.Invoke($null, @($WinRtTask))
29+
$netTask.Wait(-1) | Out-Null
30+
$netTask.Result
31+
}
32+
33+
[Windows.Devices.Radios.Radio, Windows.System.Devices, ContentType = WindowsRuntime] | Out-Null
34+
[Windows.Devices.Radios.RadioAccessStatus, Windows.System.Devices, ContentType = WindowsRuntime] | Out-Null
35+
Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
36+
$radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
37+
$bluetooth = $radios | Where-Object { $_.Kind -eq 'Bluetooth' }
38+
[Windows.Devices.Radios.RadioState, Windows.System.Devices, ContentType = WindowsRuntime] | Out-Null
39+
Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null

Maintenance/Find redundant drivers.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ function PublicStaticVoidMain {
5151
$Date = @{ Name = "Date"; Expression = { "{0:yyyy-MM-dd}" -f $_.Date } }
5252

5353
# Inventory all device drivers
54-
Write-Progress -Activity "Looking for drivers..." -Id 1
54+
Write-Progress -Activity "Inspecting drivers..." -Id 1
5555
$AllDrivers = Get-WindowsDriver -Online -All | Where-Object -FilterScript { $_.Driver -like 'oem*inf' } | Select-Object -Property $OriginalFileName, Driver, ClassDescription, ProviderName, $Date, Version
56-
Write-Progress -Activity "Looking for drivers..." -Id 1 -Completed
56+
Write-Progress -Activity "Inspecting drivers..." -Id 1 -Completed
5757

5858
# Print a list of all third-party device drivers to the verbose stream
5959
Write-Verbose $("All installed third-party drivers:`n" + ($AllDrivers | Sort-Object -Property ClassDescription | Format-Table -AutoSize -Wrap | Out-String))

0 commit comments

Comments
 (0)