-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathAddDefenderExceptions.ps1
More file actions
72 lines (62 loc) · 2.55 KB
/
AddDefenderExceptions.ps1
File metadata and controls
72 lines (62 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Run this script as Administrator
# powershell -ExecutionPolicy Bypass -File "C:\RSL\Rookie\AddDefenderExceptions.ps1"
################################################################
## Auto Elevate to Admin if not running as admin
################################################################
# Get the ID and security principal of the current user account
$WindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$WindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal ($WindowsID)
# Get the security principal for the Administrator role
$AdminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
if ($WindowsPrincipal.IsInRole($AdminRole)) {
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + " (Elevated)"
$Host.UI.RawUI.BackgroundColor = "DarkBlue"
Clear-Host
} else {
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell
$NewProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$NewProcess.Arguments = $myInvocation.MyCommand.Definition;
# Indicate that the process should be elevated
$NewProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($NewProcess);
# Exit from the current unelevated process
exit
}
write-host "Run this script from the directory root with which Rookie will be run"
start-sleep -s 5
$paths = @(
"$PSScriptRoot", # Replaces 'C:\RSL' with the script's root directory
"$PSScriptRoot\rclone",
"$PSScriptRoot\Sideloader Launcher.exe",
"$PSScriptRoot\AndroidSideloader*.exe",
"$PSScriptRoot\rclone\rclone.exe"
)
foreach ($path in $paths) {
try {
Add-MpPreference -ExclusionPath $Path -ErrorAction Stop
Write-Host "Successfully added exclusion for: $path" -ForegroundColor Green
}
catch {
Write-Host "Failed to add exclusion for: $path " -ForegroundColor Red
Write-Host "Error: $_" -ForegroundColor Red
Start-Sleep -s 5
Pause
}
}
# Verify the exclusions
Write-Host "`nCurrent exclusions:" -ForegroundColor Cyan
$defenderPreferences = Get-MpPreference
$paths | ForEach-Object {
if ($defenderPreferences.ExclusionPath -contains $_) {
Write-Host "$_ is already excluded from Defender."
} else {
Write-Host "$_ is NOT excluded from Defender."
}
}
Pause
Start-Sleep -s 5