Advertisement
jvanmelckebeke

powershell run multiple servers

Aug 25th, 2024 (edited)
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Check if any arguments were provided
  2. if ($args.Count -eq 0) {
  3.     Write-Host "Please provide the server directories as arguments. Example: .\start-minecraft-servers.ps1 A B C D"
  4.     exit
  5. }
  6.  
  7. # Get the current directory as the root directory
  8. $rootDirectory = (Get-Location).Path
  9.  
  10. # Loop through each argument and launch a Minecraft server in a new PowerShell window
  11. foreach ($server in $args) {
  12.     $serverPath = Join-Path $rootDirectory $server
  13.  
  14.     # Check if the directory exists
  15.     if (Test-Path $serverPath) {
  16.         # Set the title for the PowerShell window
  17.         $title = "Minecraft Server - $server"
  18.  
  19.         # Launch a new PowerShell window to run the Minecraft server with a title
  20.         Start-Process powershell -ArgumentList @(
  21.             "-NoExit", # Keep the new PowerShell window open
  22.             "-Command",
  23.             "Write-Host `"$title`"; cd `"$serverPath`"; java -Xmx1024M -Xms1024M -jar server.jar"
  24.         ) -NoNewWindow -Wait
  25.     } else {
  26.         Write-Host "Directory $server does not exist. Skipping..."
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement