Powershell is still not powerfull enough to do text edit via shell (ssh terminal)
71 lines
2.7 KiB
PowerShell
71 lines
2.7 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\Pyrexx.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
|
|
|
|
# Öffnet die Config in Notepad
|
|
notepad "C:\Program Files\WireGuard\Data\Configurations\Pyrexx.conf"
|
|
|
|
# Wait for Notepad to be closed
|
|
$notepadProcess = Get-Process | Where-Object { $_.ProcessName -eq "notepad" }
|
|
$notepadProcess.WaitForExit()
|
|
|
|
# Hier erstellen wir einen Registry Key mit dem Namen LimitedOperatorUI und dem wert 1
|
|
reg add HKLM\Software\WireGuard /v LimitedOperatorUI /t REG_DWORD /d 1 /f
|
|
|
|
# Wir lassen Powershell hier die vorhandenen User auflisten, um diese dann in einem Menü anzeigen zu können, statt abzutippen
|
|
$users = Get-ChildItem -Path "C:\Users" -Directory | Where-Object { $_.GetFileSystemInfos().Count -gt 0 } | ForEach-Object { $_.Name }
|
|
$possible_users = $users -join ", "
|
|
|
|
Write-Host "Wähle den Nutzer aus, der der Netzwerkkonfigurations-Operatoren Gruppe hinzugefügt werden soll:"
|
|
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 "Der Nutzer $($selected_user) wird der Netzwerkkonfigurations-Operatoren Gruppe hinzugefügt"
|
|
|
|
# Use the selected user in the next command
|
|
Add-LocalGroupMember -Group 'Netzwerkkonfigurations-Operatoren' -Member $selected_user -Verbose
|
|
} else {
|
|
Write-Host "Invalid choice"
|
|
}
|
|
|