Skip to content

Commit 9fd93fe

Browse files
author
Rajath Agasthya
committed
Revert "Disable, rather than uninstall, Windows Defender features"
This reverts commit ac6a8cf. Azure added certifications to ensure Defender is fully uninstalled, so can't just disable it.
1 parent ae4180d commit 9fd93fe

File tree

2 files changed

+1
-66
lines changed

2 files changed

+1
-66
lines changed

modules/BOSH.CFCell/BOSH.CFCell.Tests.ps1

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ Import-Module ./BOSH.CFCell.psm1
44
Remove-Module -Name BOSH.Utils -ErrorAction Ignore
55
Import-Module ../BOSH.Utils/BOSH.Utils.psm1
66

7-
#this function does not exist on VMs without Windows Defender installed
8-
function Set-MpPreference() {
9-
param(
10-
[bool]$DisableBehaviorMonitoring,
11-
[bool]$OtherThing
12-
)
13-
}
14-
157
Describe "Protect-CFCell" {
168
BeforeEach {
179
$oldWinRMStatus = (Get-Service winrm).Status
@@ -20,10 +12,6 @@ Describe "Protect-CFCell" {
2012
{ Set-Service -Name "winrm" -StartupType "Manual" } | Should Not Throw
2113

2214
Start-Service winrm
23-
24-
Mock Get-Command { [hashtable]@{ParameterSets = [hashtable]@{Parameters = @()}} } -ModuleName BOSH.CFCell
25-
Mock Write-Log {} -ModuleName BOSH.CFCell
26-
2715
}
2816

2917
AfterEach {
@@ -68,40 +56,6 @@ Describe "Protect-CFCell" {
6856
get-firewall "private" | Should be "private,Block,Allow"
6957
get-firewall "domain" | Should be "domain,Block,Allow"
7058
}
71-
72-
It "sets all Windows Defender `disable` settings to true" {
73-
Mock Get-Command {
74-
[hashtable]@{
75-
ParameterSets = [hashtable]@{
76-
Parameters = @(
77-
@{Name = "DisableBehaviorMonitoring"},
78-
@{Name = "OtherThing"}
79-
)
80-
}
81-
}
82-
} -ModuleName BOSH.CFCell
83-
Mock Set-MpPreference { } -ModuleName BOSH.CFCell
84-
85-
Protect-CFCell
86-
87-
Assert-MockCalled Write-Log -Exactly 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Disabling Windows Defender Features" }
88-
89-
Assert-MockCalled Set-MpPreference -Exactly 1 -Scope It -ParameterFilter { $DisableBehaviorMonitoring -eq $true } -ModuleName BOSH.CFCell
90-
Assert-MockCalled Set-MpPreference -Exactly 0 -Scope It -ParameterFilter { $OtherThing -eq $true } -ModuleName BOSH.CFCell
91-
92-
Assert-MockCalled Write-Log -Exactly 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Setting Defender preference DisableBehaviorMonitoring to True" }
93-
}
94-
95-
It "does not attempt to change Windows Defender settings if Windows Defender is not installed" {
96-
Mock Get-Command { $false } -ModuleName BOSH.CFCell
97-
Mock Set-MpPreference { } -ModuleName BOSH.CFCell
98-
99-
Protect-CFCell
100-
101-
Assert-MockCalled Write-Log -Exactly 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Set-MpPreference command not found, assuming Windows Defender is not installed" }
102-
Assert-MockCalled Set-MpPreference -Scope It -Exactly 0 -ModuleName BOSH.CFCell
103-
}
104-
10559
}
10660

10761
Describe "Install-CFFeatures" {

modules/BOSH.CFCell/BOSH.CFCell.psm1

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function Install-CFFeatures2016 {
6363

6464
WindowsFeatureInstall("FS-Resource-Manager")
6565
WindowsFeatureInstall("Containers")
66+
Get-WindowsFeature | Where-Object -FilterScript { $_.Name -like '*Defender*' } | Uninstall-WindowsFeature -Remove
6667

6768
Write-Log "Installed CloudFoundry Cell Windows Features"
6869

@@ -114,26 +115,6 @@ function Protect-CFCell {
114115

115116
Write-Log "Disabling NetBIOS over TCP"
116117
Disable-NetBIOS
117-
118-
Disable-WindowsDefenderFeatures
119-
}
120-
121-
function Disable-WindowsDefenderFeatures {
122-
if (Get-Command -Name Set-MpPreference -ErrorAction SilentlyContinue)
123-
{
124-
Write-Log "Disabling Windows Defender Features"
125-
(Get-Command -Name Set-MpPreference).ParameterSets.Parameters |
126-
Where-Object {
127-
$_.Name -Like "Disable*"
128-
} |
129-
ForEach-Object {
130-
Write-Log "Setting Defender preference $( $_.Name ) to True"
131-
iex "Set-MpPreference -$( $_.Name ) `$true"
132-
}
133-
}
134-
else {
135-
Write-Log "Set-MpPreference command not found, assuming Windows Defender is not installed"
136-
}
137118
}
138119

139120
function WindowsFeatureInstall {

0 commit comments

Comments
 (0)