Public/Switch-DockerContainerType.ps1

<#
    .SYNOPSIS
        This function switches Docker-For-Windows (Docker CE) from Linux Container mode to Windows Container mode
        or visa versa.
 
    .DESCRIPTION
        See .SYNOPSIS
 
    .PARAMETER ContainerType
        This parameter is MANDATORY.
 
        This parameter takes a string with a value of either "Windows" or "Linux" representing the contianer
        mode that you would like to switch to.
 
    .EXAMPLE
        # Open an elevated PowerShell Session, import the module, and -
 
        PS C:\Users\zeroadmin> Switch-DockerContainerType -ContainerType Windows
         
#>

function Switch-DockerContainerType {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$True)]
        [ValidateSet("Windows","Linux")]
        [string]$ContainerType
    )

    try {
        # Find DockerCli
        $DockerCliExePath = $(Get-ChildItem -Path "$env:ProgramFiles\Docker" -Recurse -File -Filter "*DockerCli.exe").FullName

        if (!$DockerCliExePath) {
            throw "Unable to find DockerCli.exe! Halting!"
        }
    }
    catch {
        Write-Error $_
        $global:FunctionResult = "1"
        return
    }

    $DockerInfo = Get-DockerInfo

    if ($($DockerInfo.DockerServerInfo.'OS/Arch' -match "windows" -and $ContainerType -eq "Linux") -or
    $($DockerInfo.DockerServerInfo.'OS/Arch' -match "linux" -and $ContainerType -eq "Windows")) {
        & $DockerCliExePath -SwitchDaemon

        [pscustomobject]@{
            OriginalDockerServerArch    = $DockerInfo.DockerServerInfo.'OS/Arch'
            NewDockerServerArch         = $($($(docker version) -match "OS/Arch")[1] -split ":[\s]+")[1].Trim()
        }
    }
    else {
        Write-Warning "The Docker Daemon is already set to manage $ContainerType containers! No action taken."
    }
}