Home Forums Programming Powershell Check Existence of server with search progress and time took to retrieve the server (if present in the domain) RE: Check Existence of server with search progress and time took to retrieve the server (if present in the domain)

  • Thanks Gary.

    I am learning Powershell and trying to automate few of the stuff. Hence, needed expert advice.

    **** This one I re-modified. *****

    clear-host

    $instance =""

    function checkserver

    {

    $instance= Read-Host "Enter the SQL Service Instance Name [Dont use "" "" in the servername]:"

    write-host "`n You entered server name as:["$instance.trim() "]" -ForegroundColor Yellow

    $serverObject = New-Object Microsoft.SqlServer.Management.Smo.Server($instance)

    $instance1 = $instance.toupper()

    $instance = $instance1.trim();

    $serverName = $serverObject.ComputerNamePhysicalNetBIOS

    $serverName1 = $serverName +"\"+$serverObject.InstanceName

    IF ( $serverName1 -NE "\")

    {

    write-host " `n Server: *****" "'$serverName1'" "**** exist `n" -ForegroundColor Green

    $serverName10 = $serverName1

    IF ($serverName10 -notcontains "\*"){

    write-host "'$serverName10'" is a Named Instance -ForegroundColor Magenta

    }

    ELSE {

    write-host "'$serverName10'" is a Default Instance -ForegroundColor DarkGray

    }

    }

    ELSEIF ( $serverName1 -EQ "\")

    {

    write-host "`n Wrong Server name entered:[" $instance "]" -ForegroundColor Red

    }

    }

    ## EXECUTE ##

    checkserver

    Thanks.