-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallUSBDeview.ps1
42 lines (34 loc) · 1.5 KB
/
InstallUSBDeview.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
#installUSBDeview.ps1
# Check for administrative privileges
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$1
Start-Sleep -Seconds 3
Start-Process -FilePath "powershell.exe" -ArgumentList "-ExecutionPolicy Bypass -NoProfile -File `"$PSCommandPath`"" -Verb RunAs
exit
}
Write-Host "Script is running with administrative privileges." -ForegroundColor Green
# Download and set up USBDeview
$usbDeviewUrl = "https://www.nirsoft.net/utils/usbdeview-x64.zip"
$usbDeviewZip = "$env:Temp\usbdeview-x64.zip"
$usbDeviewPath = "$env:ProgramFiles\USBDeview"
# Check if USBDeview is already installed
if (Test-Path $usbDeviewPath) {
Write-Host "USBDeview is already installed at $usbDeviewPath. Skipping installation..." -ForegroundColor Yellow
} else {
# Download USBDeview
Invoke-WebRequest -Uri $usbDeviewUrl -OutFile $usbDeviewZip
# Extract the files
Expand-Archive -Path $usbDeviewZip -DestinationPath $usbDeviewPath -Force
# Add to PATH (optional)
[Environment]::SetEnvironmentVariable("Path", "$($env:Path);$usbDeviewPath", [EnvironmentVariableTarget]::Machine)
Write-Host "USBDeview installed at $usbDeviewPath"
}
# Start USBDeview
$usbDeviewExe = "$usbDeviewPath\USBDeview.exe"
if (Test-Path $usbDeviewExe) {
Start-Process -FilePath $usbDeviewExe
Write-Host "USBDeview started successfully." -ForegroundColor Green
} else {
$1
Start-Sleep -Seconds 3
}