-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabadmin-config-usbstorage.ps1
48 lines (38 loc) · 1.17 KB
/
labadmin-config-usbstorage.ps1
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
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Enable/disable USB for storage devices connection
.PARAMETER Enable
Enable USB storage devices
.PARAMETER Disable
Disable USB storage devices
.PARAMETER Status
Show current status
.NOTES
File Name: labadmin-config-usbstorage.ps1
Author : Leonardo Marco
#>
Param(
[Parameter(Mandatory=$true, ParameterSetName='enable')]
[Switch]$Enable,
[Parameter(Mandatory=$true, ParameterSetName='disable')]
[Switch]$Disable,
[Parameter(Mandatory=$true, ParameterSetName='status')]
[Switch]$Status
)
# DISABLE
function disable {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR\" -Name "Start" -Value 4
}
# ENABLE
function enable {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR\" -Name "Start" -Value 3
}
# STATUS
function status {
if ((Get-ItemPropertyValue -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR\' -Name "Start") -eq 4) { Write-Output "Current status: DISABLED"; exit 1 }
else { Write-Output "Current status: ENABLED"; exit 0 }
}
if($disable) { disable; status }
elseif($enable) { enable; status }
else { status }