Public/Recreate-MobyLinuxVM.ps1

<#
    .SYNOPSIS
        This function recreates the MobyLinuxVM used by Docker-For-Windows to manage Linux Containers.
 
    .DESCRIPTION
        See .SYNOPSIS
 
    .NOTES
 
    .PARAMETER MobyLinuxVMMemoryInGB
        This parameter is OPTIONAL, however, it has a default value of 2.
 
        This parameter takes an integer (even numbers only) that represents the amount of Memory
        in GB to allocate to the newly recreated MobyLinuxVM.
 
    .EXAMPLE
        # Open an elevated PowerShell Session, import the module, and -
 
        PS C:\Users\zeroadmin> Recreate-MobyLinuxVM
#>

function Recreate-MobyLinuxVM {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({
            $(($_ % 2) -eq 0) -and $($_ -ge 2)
        })]
        [int]$MobyLinuxVMMemoryInGB = 2
    )

    if ([bool]$PSBoundParameters['MobyLinuxVMMemoryInGB']) {
        $MobyLinuxVMMemoryInMB = [Math]::Round($MobyLinuxVMMemoryInGB * 1KB)
    }

    try {
        $DockerDir = $($(Get-Command docker).Source -split "\\Docker\\Resources\\")[0] + "\Docker"
    }
    catch {
        Write-Error $_
        $global:FunctionResult = "1"
        return
    }

    $MobyLinuxISOPath = $(Get-ChildItem -Path "C:\Program Files\Docker" -Recurse -File -Filter "docker-for-win.iso").FullName
    if (!$MobyLinuxISOPath) {
        Write-Error "Unable to find docker-for-win.iso! Halting!"
        $global:FunctionResult = "1"
        return
    }

    if ([bool]$(Get-VM -Name MobyLinuxVM -ErrorAction SilentlyContinue)) {
        MobyLinuxBetter -Destroy
    }

    MobyLinuxBetter -VmName MobyLinuxVM -IsoFile $MobyLinuxISOPath -Create -Memory $MobyLinuxVMMemoryInMB
}