Private/GetCentOS7Scripts.ps1

function GetCentOS7Scripts {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True)]
        [string]$CentOS7PackageUrl,

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

    [System.Collections.ArrayList]$CentOS7PMInstallScript = @(
        'curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo'
        'yum install -y powershell'
    )

    [System.Collections.ArrayList]$CentOS7ManualInstallScript = @(
        "yum install $CentOS7PackageUrl"
    )

    [System.Collections.ArrayList]$CentOS7UninstallScript = @('yum 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]$CentOS7PMInstallScript
        ManualInstallScript         = [System.Collections.ArrayList]$CentOS7ManualInstallScript
        UninstallScript             = [System.Collections.ArrayList]$CentOS7UninstallScript
        ConfigurePwshRemotingScript = [System.Collections.ArrayList]$LinuxPwshRemotingScript
    }
}