Private/GetDebian9Scripts.ps1

function GetDebian9Scripts {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True)]
        [string]$Debian9PackageUrl,

        [Parameter(Mandatory=$True)]
        [string]$Debian9PackageName
    )

    $Debian9PMInstallScript = @(
        'apt-get remove -y powershell'
        'apt-get install -y curl gnupg apt-transport-https ca-certificates'
        'curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -'
        "sh -c 'echo `"deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main`" > /etc/apt/sources.list.d/microsoft.list'"
        'apt-get update'
        'apt-get install -y powershell'
    )

    [System.Collections.ArrayList]$Debian9ManualInstallScript = @(
        "ls $Debian9PackageName && rm -f $Debian9PackageName"
        "wget -q $Debian9PackageUrl"
        "dpkg -i $Debian9PackageName"
        'apt install -f'
    )

    [System.Collections.ArrayList]$Debian9UninstallScript = @('apt-get remove powershell')

    [System.Collections.ArrayList]$LinuxPwshRemotingScript = @(
        "if echo `$(cat /etc/ssh/sshd_config | grep -c '^Subsystem powershell') > /dev/null -gt 0; then sed -i '/^Subsystem powershell/d' /etc/ssh/sshd_config; fi"
        'pscorepath=$(command -v pwsh)'
        'if test -z $pscorepath; then echo pwshNotFound && exit 1; fi'
        'subsystemline=$(echo "Subsystem powershell $pscorepath -sshs -NoLogo -NoProfile")'
        'sed -i "s|sftp-server|sftp-server\n$subsystemline|" /etc/ssh/sshd_config'
        'systemctl restart sshd'
    )

    [pscustomobject]@{
        PackageManagerInstallScript = [System.Collections.ArrayList]$Debian9PMInstallScript
        ManualInstallScript         = [System.Collections.ArrayList]$Debian9ManualInstallScript
        UninstallScript             = [System.Collections.ArrayList]$Debian9UninstallScript
        ConfigurePwshRemotingScript = [System.Collections.ArrayList]$LinuxPwshRemotingScript
    }
}