PowerShell script to download and start Minecraft Server

Here’s a complete PowerShell script to download and start a Minecraft server on a clean Windows machine. Along the way the script also installs Chocolatey, and uses Chocolatey to install Java runtime.

So far I’ve only tested it on Windows Server 2012 R2 Datacenter. If anyone wants to try this script please let me know how it works out for you, it’s also on github if you want to help me improve it: https://raw.githubusercontent.com/gbowerman/azure-minecraft/master/minecraft-on-windows/minecraft-install-win.ps1

Next I’ll work on having the script create a Windows service so it’s easier to start/stop or make automatic.

$minecraftVersion = "1.8.8"
$minecraftJar = "minecraft_server." + $minecraftVersion + ".jar"
$javaInstaller = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=109717"
$clientExe = "MinecraftInstaller.msi"
$clientURL = "https://launcher.mojang.com/download/" + $clientExe
$webclient = New-Object System.Net.WebClient
$minecraftServerPath = $env:USERPROFILE + "\minecraft_server\"

# install chocolatey
(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')))>$null 2>&1

# download Minecraft client
$filePath = $env:USERPROFILE + "\Downloads\" + $clientExe
# install Minecraft client
msiexec /quiet /i $filePath

# install java
choco install -y -force javaruntime

# reload PATH
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine")
$javaCommand = get-command java.exe
$javaPath = $javaCommand.Name
$jarPath = $minecraftServerPath + $minecraftJar

# download Minecraft server
md $minecraftServerPath
$url = "https://s3.amazonaws.com/Minecraft.Download/versions/" + $minecraftVersion + "/" + $minecraftJar

# launch Minecraft server for first time
cd $minecraftServerPath

md logs
echo $null > server.properties
out-file -filepath .\banned-ips.json -encoding ascii -inputobject "[]`n"
out-file -filepath .\banned-players.json -encoding ascii -inputobject "[]`n"
out-file -filepath .\ops.json -encoding ascii -inputobject "[]`n"
out-file -filepath .\usercache.json -encoding ascii -inputobject "[]`n"
out-file -filepath .\whitelist.json -encoding ascii -inputobject "[]`n"
out-file -filepath .\eula.txt -encoding ascii -inputobject "eula=true`n"
iex "$javaPath -Xmx1024M -Xms1024M -jar $jarPath nogui"

This entry was posted in Cloud, Computers and Internet and tagged , . Bookmark the permalink.

3 Responses to PowerShell script to download and start Minecraft Server

  1. SunwolfNC says:

    It’s been a couple years so I’m assuming there wasn’t a Gen2 of this?
    Did you find that someone had something already out there people were using?

  2. sendmarsh says:

    Thanks for checking back on this. Someone did create a Windows version for Azure here: https://github.com/DCtheGeek/AzureMinecraft/tree/master/SingleServer – you can ignore the azure part and look at the PowerShell script to install Minecraft on Windows: https://github.com/DCtheGeek/AzureMinecraft/blob/master/SingleServer/DSC_SingleServer.ps1 – I’ve not tried it but I’m guessing it does more than the script above. Let me know if you try it.

    • SunwolfNC says:

      Hey, thanks for quick reply!
      I’ll likely parse it and check out and if I end up using it on our servers, I’ll circle back with how it’s setup and running for us

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s