Category: Minecraft Server (Windows 10 Edition)


Minecraft PE / Bedrock Windows Automatic update script (Windows PowerShell)

By Robin (SYNTEX),

Create a new PowerShell file .ps1

$gameDir = "C:\MCServer"

cd $gameDir

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"

$result = Invoke-WebRequest -Uri https://minecraft.net/en-us/download/server/bedrock/
$serverurl = $result.Links | select href | where {$_.href -like "https://minecraft.azureedge.net/bin-win/bedrock-server*"}
$url = $serverurl.href
$filename = $url.Replace("https://minecraft.azureedge.net/bin-win/","")
$filename

$url = "$url"
$output = "$gameDir\$filename"

if(!(get-item $output)){
    Stop-Process -name "bedrock_server"

    # DO AN BACKUP OF CONFIG
    New-Item -ItemType Directory -Name backup
    Copy-Item -Path "server.properties" -Destination backup
    Copy-Item -Path "whitelist.json" -Destination backup
    Copy-Item -Path "permissions.json" -Destination backup

    $start_time = Get-Date

    Invoke-WebRequest -Uri $url -OutFile $output
    Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
    Expand-Archive -LiteralPath $output -DestinationPath C:\MCServer -Force

    # RECOVER BACKUP OF CONFIG
    Copy-Item -Path ".\backup\server.properties" -Destination .\
    Copy-Item -Path ".\backup\whitelist.json" -Destination .\
    Copy-Item -Path ".\backup\permissions.json" -Destination .\

}

if(!(get-process -name bedrock_server)){
    Start-Process -FilePath bedrock_server.exe
}

Create a new Windows task

Open Computer Management

Goto Task Schedular

Under General tick “Run whether user is logged on or not”

Trigger

Begin the task: On a schedule
Settings: Daily at 4:00:00 AM