检测是否已安装telnet-client的功能

时间:2019-01-31 23:27:27

标签: powershell

function add-TelNet
{
    param([string]$telnot)
    $service= Get-WindowsFeature $telnot -ErrorAction SilentlyContinue #telnet-client

    if(Get-WindowsFeature $service -ErrorAction SilentlyContinue)
    {
        if((Get-WindowsFeature $service).status -eq 'Installed')
        {
            echo "Telnet-client service is already running."

        foreach ($service in $services)
        {
      else
      {
            try
            {
                echo "Installing telnet-client to computer. Please wait for install to finish"
                Import-Module servermanager
                Add-WindowsFeature telnet-client
                new-Item -Path $env:USERPROFILE -Name "feature.log" -ItemType file -Value "Telnet-client is installed."
                echo "Telnet-client has been installed on your computer"
            }
            catch
            {
                echo "ERROR: $service Could not install!"
            }
       }
        }
        }
    }
}

我需要检查是否安装了telnet,如果没有安装,请检查。当我运行时,什么也没有发生。我认为它甚至都不会检查是否已安装telnet-client

1 个答案:

答案 0 :(得分:0)

    function add-telnet
{
    $telnot = Get-WindowsFeature telnet-client -ErrorAction SilentlyContinue
    if (($telnot).installstate -eq "Available")
    {
        try
        {
            echo "Installing telnet-client to computer. Please wait for install to finish"
            Import-Module servermanager
            Add-WindowsFeature telnet-client
            new-Item -Path $env:USERPROFILE -Name "feature.log" -ItemType file -Value "telnet installed "
            echo "Telnet-client has been installed on your computer"
            Get-WindowsFeature telnet-client | Add-Content -Path $env:USERPROFILE/feature.log
            Get-WindowsFeature telnet-client
        }
        Catch
        {
            echo "Unable to install Telnet-Client. Please contact your System Administrator."
        }

    }
    else
      {
        echo "Telnet-client is already installed."
      }
}

我知道了。