Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Check if any arguments were provided
- if ($args.Count -eq 0) {
- Write-Host "Please provide the server directories as arguments. Example: .\start-minecraft-servers.ps1 A B C D"
- exit
- }
- # Get the current directory as the root directory
- $rootDirectory = (Get-Location).Path
- # Loop through each argument and launch a Minecraft server in a new PowerShell window
- foreach ($server in $args) {
- $serverPath = Join-Path $rootDirectory $server
- # Check if the directory exists
- if (Test-Path $serverPath) {
- # Set the title for the PowerShell window
- $title = "Minecraft Server - $server"
- # Launch a new PowerShell window to run the Minecraft server with a title
- Start-Process powershell -ArgumentList @(
- "-NoExit", # Keep the new PowerShell window open
- "-Command",
- "Write-Host `"$title`"; cd `"$serverPath`"; java -Xmx1024M -Xms1024M -jar server.jar"
- ) -NoNewWindow -Wait
- } else {
- Write-Host "Directory $server does not exist. Skipping..."
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement