Skip to content

Commit 69331f6

Browse files
committed
Powershell: remove unused functions
1 parent 10a2f88 commit 69331f6

File tree

2 files changed

+1
-267
lines changed

2 files changed

+1
-267
lines changed

modules/BOSH.WindowsUpdates/BOSH.WindowsUpdates.Tests.ps1

Lines changed: 1 addition & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ Describe "BOSH.WindowsUpdates" {
1414
Describe "Disable-AutomaticUpdates" {
1515
BeforeEach {
1616
$oldWuauStatus = (Get-Service wuauserv).Status
17-
$oldWuauStartMode = ( Get-Service wuauserv).StartType
17+
$oldWuauStartMode = (Get-Service wuauserv).StartType
1818

1919
{ Set-Service -Name wuauserv -StartupType "Manual" } | Should -Not -Throw
2020
{ Set-Service -Name wuauserv -Status "Running" } | Should -Not -Throw
2121

22-
2322
$oldAUOptions = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update').AUOptions
2423
$oldEnableFeaturedSoftware = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update').EnableFeaturedSoftware
2524
$oldIncludeRecUpdates = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update').IncludeRecommendedUpdates
@@ -80,185 +79,4 @@ Describe "BOSH.WindowsUpdates" {
8079
(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update').IncludeRecommendedUpdates | Should -Be "0"
8180
}
8281
}
83-
84-
Describe "Enable-SecurityPatches" {
85-
It "enables CVE-2015-6161" {
86-
$handlerHardeningPath32Exists = $false
87-
$oldIExplore32 = ""
88-
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING")
89-
{
90-
$handlerHardeningPathExists32 = $true
91-
$oldIExplore32 = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING").'iexplore.exe'
92-
}
93-
94-
$handlerHardeningPath64Exists = $false
95-
$oldIExplore64 = ""
96-
if (Test-Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING")
97-
{
98-
$handlerHardeningPath64Exists = $true
99-
$oldIExplore64 = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING").'iexplore.exe'
100-
}
101-
102-
{ Enable-CVE-2015-6161 } | Should -Not -Throw
103-
104-
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING").'iexplore.exe' | Should -Be "1"
105-
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING").'iexplore.exe' | Should -Be "1"
106-
107-
if ($handlerHardeningPath32Exists)
108-
{
109-
if ($oldIExplore32 -eq "")
110-
{
111-
Remove-Item-Property -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING" -Name "iexplore.exe"
112-
}
113-
else
114-
{
115-
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING" -Value $oldIExplore32 -Name "iexplore.exe"
116-
}
117-
}
118-
else
119-
{
120-
Remove-Item "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING"
121-
}
122-
123-
if ($handlerHardeningPath32Exists)
124-
{
125-
if ($oldIExplore64 -eq "")
126-
{
127-
Remove-Item-Property -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING" -Name "iexplore.exe"
128-
}
129-
else
130-
{
131-
Set-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING" -Value $oldIExplore64 -Name "iexplore.exe"
132-
}
133-
}
134-
else
135-
{
136-
Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING"
137-
}
138-
}
139-
140-
It "enables CVE-2017-8529" {
141-
$disclosureFixPathExists32 = $false
142-
$oldIExplore32 = ""
143-
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX")
144-
{
145-
$disclosureFixPathExists32 = $true
146-
$oldIExplore32 = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX").'iexplore.exe'
147-
}
148-
149-
$disclosureFixPathExists64 = $false
150-
$oldIExplore64 = ""
151-
if (Test-Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX")
152-
{
153-
$disclosureFixPathExists64 = $true
154-
$oldIExplore64 = (Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX").'iexplore.exe'
155-
}
156-
157-
{ Enable-CVE-2017-8529 } | Should -Not -Throw
158-
159-
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX").'iexplore.exe' | Should -Be "1"
160-
(Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX").'iexplore.exe' | Should -Be "1"
161-
162-
if ($disclosureFixPathExists32)
163-
{
164-
if ($oldIExplore32 -eq "")
165-
{
166-
Remove-Item-Property -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX" -Name "iexplore.exe"
167-
}
168-
else
169-
{
170-
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX" -Value $oldIExplore32 -Name "iexplore.exe"
171-
}
172-
}
173-
else
174-
{
175-
Remove-Item "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX"
176-
}
177-
178-
if ($disclosureFixPathExists64)
179-
{
180-
if ($oldIExplore64 -eq "")
181-
{
182-
Remove-Item-Property -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX" -Name "iexplore.exe"
183-
}
184-
else
185-
{
186-
Set-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX" -Value $oldIExplore64 -Name "iexplore.exe"
187-
}
188-
}
189-
else
190-
{
191-
Remove-Item "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX"
192-
}
193-
}
194-
195-
It "enables CredSSP" {
196-
$credSSPPathExists = $false
197-
$credSSPParamPathExists = $false
198-
$oldEcryptOracle = ""
199-
if (Test-Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP")
200-
{
201-
$credSSPPathExists = $true
202-
if (Test-Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters")
203-
{
204-
$credSSPParamPathExists = $true
205-
$oldEcryptOracle = (Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters").AllowEncryptionOracle
206-
}
207-
}
208-
209-
{ Enable-CredSSP } | Should -Not -Throw
210-
211-
(Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters").AllowEncryptionOracle | Should -Be "1"
212-
213-
if ($credSSPPathExists)
214-
{
215-
if ($credSSPParamPathExists)
216-
{
217-
if ($oldEcryptOracle -eq "")
218-
{
219-
Remove-Item-Property -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters" -Name "AllowEncryptionOracle"
220-
}
221-
else
222-
{
223-
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters" -Value $oldEcryptOracle -Name "AllowEncryptionOracle"
224-
}
225-
}
226-
else
227-
{
228-
Remove-Item "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters"
229-
}
230-
}
231-
else
232-
{
233-
Remove-Item "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP" -Recurse
234-
235-
}
236-
}
237-
}
238-
239-
Describe "Upgrade-PSVersion" {
240-
It "Only installs if powershell 5.1 or above is not installed" {
241-
Mock -ModuleName BOSH.WindowsUpdates Test-PSVersion { $true }
242-
Mock -ModuleName BOSH.WindowsUpdates Invoke-WebRequest { }
243-
Mock -ModuleName BOSH.WindowsUpdates Start-Process { }
244-
245-
{ Upgrade-PSVersion } | Should -Not -Throw
246-
247-
Assert-MockCalled Test-PSVersion -Times 1 -Scope It -ModuleName BOSH.WindowsUpdates
248-
Assert-MockCalled Invoke-WebRequest -Times 0 -Scope It -ModuleName BOSH.WindowsUpdates
249-
Assert-MockCalled Start-Process -Times 0 -Scope It -ModuleName BOSH.WindowsUpdates
250-
}
251-
252-
It "Only installs if powershell 5.1 or above is not installed" {
253-
Mock -ModuleName BOSH.WindowsUpdates Test-PSVersion { $false }
254-
Mock -ModuleName BOSH.WindowsUpdates Invoke-WebRequest { }
255-
Mock -ModuleName BOSH.WindowsUpdates Start-Process { }
256-
257-
{ Upgrade-PSVersion } | Should -Not -Throw
258-
259-
Assert-MockCalled Test-PSVersion -Times 1 -Scope It -ModuleName BOSH.WindowsUpdates
260-
Assert-MockCalled Invoke-WebRequest -Times 1 -Scope It -ParameterFilter { $Uri -eq "https://go.microsoft.com/fwlink/?linkid=839516" -and $Outfile -eq "C:\provision\PS51.msu" -and $UseBasicParsing.IsPresent } -ModuleName BOSH.WindowsUpdates
261-
Assert-MockCalled Start-Process -Times 1 -Scope It -ParameterFilter { $FilePath -eq "C:\provision\PS51.msu" -and $ArgumentList -eq '/quiet /norestart /log:"C:\provision\psupgrade.log"' -and $Wait.IsPresent -and $Passthru.IsPresent } -ModuleName BOSH.WindowsUpdates
262-
}
263-
}
26482
}

modules/BOSH.WindowsUpdates/BOSH.WindowsUpdates.psm1

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ function Wait-WindowsUpdates {
4848
}
4949

5050
function Install-WindowsUpdates {
51-
5251
# Set registry key so that we will receive the Jan 2018 patches (KB4056895)
5352
REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat /f /v cadca5fe-87d3-4b96-b7fb-a231484277cc /t REG_DWORD /d 0
5453

@@ -299,86 +298,3 @@ function Get-UpdateBatch {
299298
$script:MoreUpdates=0
300299
}
301300
}
302-
303-
function Search-InstalledUpdates {
304-
$Session = New-Object -ComObject Microsoft.Update.Session
305-
$Searcher = $Session.CreateUpdateSearcher()
306-
$Searcher.Search("IsInstalled=1").Updates | Sort-Object LastDeploymentChangeTime | ForEach-Object { "KB$($_.KBArticleIDs) | $($_.Title)" }
307-
}
308-
309-
function Test-InstalledUpdates {
310-
Write-Host "Running Get-HotFix:"
311-
Get-HotFix
312-
$Session = New-Object -ComObject Microsoft.Update.Session
313-
Write-Host "Session: $Session"
314-
$Searcher = $Session.CreateUpdateSearcher()
315-
Write-Host "Searcher: $Searcher"
316-
$UninstalledUpdates = $Searcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0").Updates
317-
if ($UninstalledUpdates.Count -ne 0) {
318-
Write-Log "The following updates are not currently installed:"
319-
foreach ($Update in $UninstalledUpdates) {
320-
Write-Log "> $($Update.Title)"
321-
}
322-
Throw 'There are uninstalled updates'
323-
}
324-
}
325-
326-
<#
327-
.Synopsis
328-
Disable Automatic Updates
329-
.Description
330-
This cmdlet disables automatic Windows Updates
331-
#>
332-
function Disable-AutomaticUpdates {
333-
Stop-Service -Name wuauserv
334-
Set-Service -Name wuauserv -StartupType Disabled
335-
336-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' -Value 1 -Name 'AUOptions'
337-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' -Value 0 -Name 'EnableFeaturedSoftware'
338-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' -Value 0 -Name 'IncludeRecommendedUpdates'
339-
}
340-
341-
function Enable-CVE-2015-6161 {
342-
#Enable MS15-124 - Internet Explorer ASLR Bypass fix - CVE-2015-6161
343-
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING" /t REG_DWORD /v "iexplore.exe" /d 1 /f
344-
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ALLOW_USER32_EXCEPTION_HANDLER_HARDENING" /t REG_DWORD /v "iexplore.exe" /d 1 /f
345-
}
346-
347-
function Enable-CVE-2017-8529 {
348-
#Enable Microsoft Browser Information Disclosure Vulnerability - CVE-2017-8529
349-
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX" /v iexplore.exe /t REG_DWORD /d 1 /f
350-
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_PRINT_INFO_DISCLOSURE_FIX" /v iexplore.exe /t REG_DWORD /d 1 /f
351-
352-
}
353-
354-
function Enable-CredSSP {
355-
#Enable CredSSP updates - CVE-2018-0886
356-
#Policy set to "mitigated"
357-
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters" /v AllowEncryptionOracle /t REG_DWORD /d 1 /f
358-
}
359-
360-
function Upgrade-PSVersion {
361-
if (Test-PSVersion) {
362-
Write-Log "Upgrade-PSVersion: No need to upgrade. PSVersion is 5 or above"
363-
return
364-
}
365-
366-
$existingProtocol = [Net.ServicePointManager]::SecurityProtocol
367-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
368-
Write-Log "Upgrade-PSVersion: Downloading."
369-
370-
$MSUPath = "c:\provision\PS51.msu"
371-
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=839516" -UseBasicParsing -OutFile $MSUPath
372-
373-
Write-Log "Upgrade-PSVersion: Downloaded. Installing."
374-
375-
$p = Start-Process -FilePath $MSUPath -ArgumentList '/quiet /norestart /log:"C:\provision\psupgrade.log"' -Wait -PassThru
376-
Write-Log "Upgrade-PSVersion: Installed. Process exit code: $($p.ExitCode)"
377-
[Net.ServicePointManager]::SecurityProtocol = $existingProtocol
378-
}
379-
380-
function Test-PSVersion {
381-
$version = $PSVersionTable.PSVersion
382-
Write-Log "Powershell is $version"
383-
$version.Major -ge 5
384-
}

0 commit comments

Comments
 (0)