-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSetupDevDrive.ps1
More file actions
159 lines (142 loc) · 6.02 KB
/
Copy pathSetupDevDrive.ps1
File metadata and controls
159 lines (142 loc) · 6.02 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Function to check if a drive is a Dev Drive
function Get-DevDrive {
$devDrives = Get-Volume | Where-Object { $_.FileSystemType -eq 'ReFS' -and $_.DriveType -eq 'Fixed' }
$devDriveLetters = @()
foreach ($drive in $devDrives) {
$driveLetter = "$($drive.DriveLetter):"
Write-Host "`nDev Drive found: $driveLetter"
$devDriveLetters += $driveLetter
}
if ($devDriveLetters.Count -eq 0) {
Write-Output "No Dev Drive found on the system."
return $null
} elseif ($devDriveLetters.Count -eq 1) {
return $devDriveLetters[0]
} else {
Write-Host "Multiple Dev Drives found:"
for ($i = 0; $i -lt $devDriveLetters.Count; $i++) {
Write-Host "[$i] $($devDriveLetters[$i])"
}
$selection = Read-Host "Please select the drive you want to configure by entering the corresponding number"
if ($selection -match '^\d+$' -and [int]$selection -lt $devDriveLetters.Count) {
return $devDriveLetters[$selection]
} else {
Write-Output "Invalid selection. Exiting script."
return $null
}
}
}
# Function to test if a Dev Drive is trusted
function Test-DevDriveTrusted {
param (
[string]$DriveLetter
)
$result = fsutil devdrv query $DriveLetter | Out-String
return $result -match "This is a trusted developer volume"
}
# Function to get allowed filters on a Dev Drive
function Get-DevDriveAllowedFilters {
param (
[string]$DriveLetter
)
$result = fsutil devdrv query $DriveLetter | Out-String
if ($result -match "Filters allowed on this developer volume:\s*(.*)") {
$allowedFiltersLine = $matches[1]
$allowedFiltersLine = $allowedFiltersLine.Trim()
return $allowedFiltersLine -split ",\s*"
}
return @()
}
# Function to add filters to a Dev Drive
function Add-DevDriveFilters {
param (
[string]$DriveLetter,
[string[]]$Filters
)
$allowedFilters = Get-DevDriveAllowedFilters -DriveLetter $DriveLetter
$filtersToAdd = $Filters | Where-Object { $allowedFilters -notcontains $_ }
if ($filtersToAdd.Count -gt 0) {
$filterString = $filtersToAdd -join ","
try {
fsutil devdrv setfiltersallowed /f /volume $DriveLetter $filterString > $null
Write-Output "Filters added to $DriveLetter $filterString"
} catch {
Write-Error "Failed to add filters to $DriveLetter $_"
}
} else {
Write-Output "All specified filters are already allowed on $DriveLetter."
}
}
# Function to prompt the user to add filters
function PromptForFilters {
param (
[string]$DriveLetter
)
$filters = @()
Write-Host "Default filters: PrjFlt, bindFlt, wcifs, FileInfo, ProcMon24"
$defaultResponse = Read-Host "Would you like to use the default filters? (Y/N)"
if ($defaultResponse -eq 'Y') {
$filters += "PrjFlt", "bindFlt", "wcifs", "FileInfo", "ProcMon24"
} else {
$filterOptions = @(
@{ Name = "PrjFlt"; Description = "GVFS: Sparse enlistments of Windows" },
@{ Name = "MsSecFlt"; Description = "MSSense: Microsoft Defender for Endpoint for EDR Sensor" },
@{ Name = "WdFilter"; Description = "Defender: Windows Defender Filter" },
@{ Name = "bindFlt, wcifs"; Description = "Docker: Running containers out of Dev Drive" },
@{ Name = "FileInfo"; Description = "Windows Performance Recorder: Measure file system operations & Resource Monitor: Shows resource usage. Required to show file names in Disk Activity" },
@{ Name = "ProcMon24"; Description = "Process Monitor - Sysinternals: Monitor file system activities [EXPERIMENTAL]" },
@{ Name = "WinSetupMon"; Description = "Windows Upgrade: Used during OS Upgrade. Required if user moves TEMP environment variable to Dev Drive" }
)
foreach ($option in $filterOptions) {
$response = Read-Host "Do you want to add the filter $($option.Name) - $($option.Description)? (Y/N)"
if ($response -eq 'Y') {
$filters += $option.Name -split ',\s*'
}
}
}
Add-DevDriveFilters -DriveLetter $DriveLetter -Filters $filters
}
# Function to check if the Anti-Virus filter is enabled and give the option to change it
function ManageAntiVirusFilter {
param (
[string]$DriveLetter
)
$result = fsutil devdrv query $DriveLetter | Out-String
$avEnabled = $result -match "Developer volumes are protected by antivirus filter"
if ($avEnabled) {
Write-Host "Developer volumes are currently protected by antivirus filter."
$response = Read-Host "Do you want to disable the antivirus filter? (Y/N)"
if ($response -eq 'Y') {
fsutil devdrv enable /disallowAV > $null
Write-Output "Antivirus filter has been disabled for Dev Drive $DriveLetter."
}
} else {
Write-Host "Developer volumes are not protected by antivirus filter."
$response = Read-Host "Do you want to enable the antivirus filter? (Y/N)"
if ($response -eq 'Y') {
fsutil devdrv enable /allowAV > $null
Write-Output "Antivirus filter has been enabled for Dev Drive $DriveLetter."
}
}
}
# Main Script
$devDrive = Get-DevDrive
if ($null -ne $devDrive) {
$isTrusted = Test-DevDriveTrusted -DriveLetter $devDrive
if (-not $isTrusted) {
$userResponse = Read-Host "`nDev Drive $devDrive is not trusted. Do you want to set it as trusted? (Y/N)"
if ($userResponse -eq 'Y') {
fsutil devdrv trust $devDrive > $null
Write-Output "Dev Drive $devDrive has been set as trusted."
} else {
Write-Output "Dev Drive $devDrive remains untrusted."
exit
}
} else {
Write-Output "`nDev Drive $devDrive is already trusted."
}
ManageAntiVirusFilter -DriveLetter $devDrive
PromptForFilters -DriveLetter $devDrive
} else {
Write-Output "No Dev Drive found to configure."
}