quick_wireguardtest/WireWin.ps1

62 lines
2.1 KiB
PowerShell

# Überprüfe ob powershellscripte ausgeführt werden dürfen
if ((Get-ExecutionPolicy) -eq "Restricted") {
Set-ExecutionPolicy RemoteSigned
}
# Überprüfe ob chocolatey installiert ist
if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) {
# Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
# Installiere Wireguard mit chocolatey
if (choco install wireguard -y) {
Write-Host "WireGuard wurde erfolgreich installiert."
} else {
Write-Host "WireGuard konnte nicht installiert werden."
exit
}
# Erstelle Verzeichnis zum speichern von WireGuard Konfigurationen
New-Item -ItemType Directory -Path "C:\Program Files\WireGuard\Data\Configurations\"
# Erstelle WireGuard Konfiguration
New-Item -ItemType File -Path "C:\Program Files\WireGuard\Data\Configurations\wg0.conf"
# Eingabe für die Wireguard Configuration:
Write-Host "Gebe hier die Wireguard Konfiguration ein: (Zweimal auf Enter drücken zum bestätigen)"
$config = ""
do {
$line = Read-Host
if ($line -ne "") {
$config += $line + "`n" # `n is the newline character
}
} until ($line -eq "")
# Füge die Konfiguration an die wg0.conf an
Add-Content -Path "C:\Program Files\WireGuard\Data\Configurations\wg0.conf" -Value $config
reg add HKLM\Software\WireGuard /v LimitedOperatorUI /t REG_DWORD /d 1 /f
$users = Get-ChildItem -Path "C:\Users" -Directory | Where-Object { $_.GetFileSystemInfos().Count -gt 0 } | ForEach-Object { $_.Name }
$possible_users = $users -join ", "
Write-Host "Please choose a user:"
for ($i=0; $i -lt $users.Count; $i++) {
Write-Host "$i. $($users[$i])"
}
$choice = Read-Host "Enter the number of the user you want to choose (0-$($users.Count - 1))"
if ($choice -ge 0 -and $choice -lt $users.Count) {
$selected_user = $users[$choice]
Write-Host "You selected $($selected_user)"
# Use the selected user in the next command
Add-LocalGroupMember -Group 'Netzwerkkonfigurations-Operatoren' -Member $selected_user -Verbose
} else {
Write-Host "Invalid choice"
}