add Paramter Switch for IP
This commit is contained in:
parent
2bf8287cb5
commit
46d925d6bb
@ -1,3 +1,16 @@
|
|||||||
@echo off
|
@echo off
|
||||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File Set-ELP-Host.ps1
|
setlocal
|
||||||
pause
|
|
||||||
|
REM Set the path to the PowerShell script
|
||||||
|
set SCRIPT_PATH=Set-ELP-Host.ps1
|
||||||
|
|
||||||
|
REM Check if an IP was passed as a parameter to the batch file
|
||||||
|
if "%~1"=="" (
|
||||||
|
REM No parameter passed: run script in interactive mode
|
||||||
|
powershell.exe -ExecutionPolicy Bypass -File "%SCRIPT_PATH%"
|
||||||
|
) else (
|
||||||
|
REM Parameter passed: run script with DirektIP argument
|
||||||
|
powershell.exe -ExecutionPolicy Bypass -File "%SCRIPT_PATH%" -DirektIP "%~1"
|
||||||
|
)
|
||||||
|
|
||||||
|
endlocal
|
||||||
|
|||||||
109
Set-ELP-Host.ps1
109
Set-ELP-Host.ps1
@ -1,74 +1,101 @@
|
|||||||
# Path INI-Datei
|
param(
|
||||||
|
[string]$DirektIP # Optional parameter to directly set the IP address
|
||||||
|
)
|
||||||
|
|
||||||
|
# Define paths
|
||||||
$iniPath = "C:\EDP\ELP\ELP.ini"
|
$iniPath = "C:\EDP\ELP\ELP.ini"
|
||||||
|
$exePath = "C:\EDP\ELP\ELP.exe"
|
||||||
|
|
||||||
Write-Host "`n"
|
# Function to update the Host= entry in the INI file
|
||||||
|
function SetHostIP($ip)
|
||||||
|
{
|
||||||
|
if (Test-Path $iniPath)
|
||||||
|
{
|
||||||
|
$iniContent = Get-Content $iniPath
|
||||||
|
$iniContent = $iniContent -replace '^Host=.*$', "Host=$ip"
|
||||||
|
Set-Content -Path $iniPath -Value $iniContent
|
||||||
|
Write-Host "Der EDP-Server wurde auf '$ip' gesetzt." -ForegroundColor Green
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "INI-Datei '$iniPath' wurde nicht gefunden." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Print menue
|
# Function to start the EDP application
|
||||||
Write-Host "Bitte EDP-Server bestimmen:`n"
|
function StartEDP()
|
||||||
|
{
|
||||||
|
if (Test-Path $exePath)
|
||||||
|
{
|
||||||
|
Write-Host "Starte EDP Einsatzleitplatz..."
|
||||||
|
Start-Process $exePath
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "Die Anwendung '$exePath' wurde nicht gefunden." -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# If a parameter is provided, directly set IP and start EDP
|
||||||
|
if ($DirektIP)
|
||||||
|
{
|
||||||
|
SetHostIP -ip $DirektIP
|
||||||
|
StartEDP
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Interactive menu if no parameter was passed
|
||||||
|
Write-Host "`nBitte EDP-Server bestimmen:`n"
|
||||||
Write-Host "1 = 192.168.112.10 (ELW RK TUT 50/11-1)"
|
Write-Host "1 = 192.168.112.10 (ELW RK TUT 50/11-1)"
|
||||||
Write-Host "2 = 172.20.2.101 (DRK Spaichingen)"
|
Write-Host "2 = 172.20.2.101 (DRK Spaichingen)"
|
||||||
# Write-Host "3 = edp-schulung.drk-spa.de (DRK Schulung)"
|
# Write-Host "3 = edp-schulung.drk-spa.de (DRK Schulung)"
|
||||||
Write-Host "9 = 127.0.0.1 (Lokaler Server)"
|
Write-Host "9 = 127.0.0.1 (Lokaler Server)"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
# Read userinput
|
# Get user input
|
||||||
$wahl = Read-Host "Ihre Auswahl (1 bis 9)"
|
$selection = Read-Host "Ihre Auswahl (1 bis 9)"
|
||||||
|
|
||||||
# select IP from userinput
|
# Map selection to IP address
|
||||||
switch ($wahl)
|
switch ($selection)
|
||||||
{
|
{
|
||||||
"1"
|
"1"
|
||||||
{
|
{
|
||||||
$neueIP = "192.168.112.10"
|
$newIP = "192.168.112.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
"2"
|
"2"
|
||||||
{
|
{
|
||||||
$neueIP = "172.20.2.101"
|
$newIP = "172.20.2.101"
|
||||||
}
|
}
|
||||||
|
|
||||||
"3"
|
"3"
|
||||||
{
|
{
|
||||||
$neueIP = "edp-schulung.drk-spa.de"
|
$newIP = "edp-schulung.drk-spa.de"
|
||||||
}
|
}
|
||||||
|
|
||||||
"9"
|
"9"
|
||||||
{
|
{
|
||||||
$neueIP = "127.0.0.1"
|
$newIP = "127.0.0.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
Default
|
Default
|
||||||
{
|
{
|
||||||
Write-Host "Unbekannte Auswahl. Vorgang abgebrochen." -ForegroundColor Red
|
Write-Host "Ungültige Auswahl. Vorgang abgebrochen." -ForegroundColor Red
|
||||||
exit
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# read ini File
|
# Apply change
|
||||||
if (Test-Path $iniPath)
|
SetHostIP -ip $newIP
|
||||||
|
|
||||||
|
# Ask whether to start the EDP app
|
||||||
|
$startChoice = Read-Host "Soll EDP Einsatzleitplatz gestartet werden? (Y/n)"
|
||||||
|
if ($startChoice -in @("Y", "y", "1", ""))
|
||||||
{
|
{
|
||||||
$iniInhalt = Get-Content $iniPath
|
StartEDP
|
||||||
|
|
||||||
# find line with "Hosts= and replace IP
|
|
||||||
$iniInhalt = $iniInhalt -replace '^Host=.*$', "Host=$neueIP"
|
|
||||||
|
|
||||||
# Write INI File
|
|
||||||
Set-Content -Path $iniPath -Value $iniInhalt
|
|
||||||
|
|
||||||
#Print promt
|
|
||||||
Write-Host "`nDer EDP-Server wurde auf '$neueIP' gewechselt." -ForegroundColor Green
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#Print Errer 404
|
Write-Host "EDP wird nicht gestartet."
|
||||||
Write-Host "Die Datei '$iniPath' wurde nicht gefunden." -ForegroundColor Red
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
$wahl = Read-Host "Soll EDP Einsatzleitplatz gestartet werden? (Y/n)"
|
|
||||||
|
|
||||||
if ($wahl -in @("Y", "y", "1", ""))
|
|
||||||
{
|
|
||||||
Write-Host "Starte EDP Einsatzleitplatz..."
|
|
||||||
Start-Process "C:\EDP\ELP\ELP.exe"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Write-Host "EDP wird nicht gestartet"
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user