Windows Vista Forums

Can anyone help
  1. #1


    ted Guest

    Can anyone help

    I am trying to write a powershell script in order to grep out a number
    of servers from a text file and list them, so I can say press 1 and it
    will log me on to that server or 2 or 3 or 4 and so on.
    I have this code so far.



    Regards,

    Terry
    Echo " Please Enter Instance Name, I.E IBTKYPSP32B034\HOSTED_P1"
    $a = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
    foreach($a in get-content "C:\CheckSQLServer\sql\SQLTokyo.txt")
    {
    $searchstr = Read-Host "Please enter the SQL Server Instance
    name"
    if ($a -eq"IBTKY")
    Echo Print $a
    {$SearchStr+ ""; sqlcmd -S $a -E}
    elseif ($a -eq "q")
    break

    }


    end

      My System SpecsSystem Spec

  2. #2


    Oisin (x0n) Grehan [MVP] Guest

    Re: Can anyone help

    On Jul 30, 1:30*am, ted <Terry.J...@xxxxxx> wrote:

    > I am trying to write a powershell script in order to grep out a number
    > of servers from a text file and list them, so I can say press 1 and it
    > will log me on to that server or 2 or 3 or 4 and so on.
    > I have this code so far.
    >
    > Regards,
    >
    > Terry
    > Echo " Please Enter Instance Name, I.E IBTKYPSP32B034\HOSTED_P1"
    > * * * * $a = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
    > * * * * * * * * foreach($a in get-content "C:\CheckSQLServer\sql\SQLTokyo.txt")
    > * * * * {
    > * * * * * * * * $searchstr = Read-Host "Please enter the SQL Server Instance
    > name"
    > * * * * * * * * * * * * if ($a -eq"IBTKY")
    > * * Echo Print $a
    > * * * * * * * * * * * * * * * * * * * * {$SearchStr+ ""; sqlcmd -S $a -E}
    > * * * * * * * * * * * * elseif ($a -eq "q")
    > * * * * * * * * * * * * * * * * break
    >
    > * * * * * * * * }
    >
    > end
    it's very difficult to work out what you want from that snippet of
    source. why not show us a sample of the .txt file (strip out any
    sensitive servernames with fakes) and an example saerch string, the
    results you want to see from that and what the options should be from
    there.

    - Oisin

      My System SpecsSystem Spec

  3. #3


    ted Guest

    Re: Can anyone help

    On Jul 31, 5:05 am, "Oisin (x0n) Grehan [MVP]" <ois...@xxxxxx>
    wrote:

    > On Jul 30, 1:30 am, ted <Terry.J...@xxxxxx> wrote:
    >
    >
    >

    > > I am trying to write a powershell script in order to grep out a number
    > > of servers from a text file and list them, so I can say press 1 and it
    > > will log me on to that server or 2 or 3 or 4 and so on.
    > > I have this code so far.
    >

    > > Regards,
    >

    > > Terry
    > > Echo " Please Enter Instance Name, I.E IBTKYPSP32B034\HOSTED_P1"
    > > $a = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
    > > foreach($a in get-content "C:\CheckSQLServer\sql\SQLTokyo.txt")
    > > {
    > > $searchstr = Read-Host "Please enter the SQL Server Instance
    > > name"
    > > if ($a -eq"IBTKY")
    > > Echo Print $a
    > > {$SearchStr+ ""; sqlcmd -S $a -E}
    > > elseif ($a -eq "q")
    > > break
    >

    > > }
    >

    > > end
    >
    > it's very difficult to work out what you want from that snippet of
    > source. why not show us a sample of the .txt file (strip out any
    > sensitive servernames with fakes) and an example saerch string, the
    > results you want to see from that and what the options should be from
    > there.
    >
    > - Oisin
    Hi there Oisin,

    Thank you for your reply

    This is what I would like this one is written with unix shell however
    as its unix it wont work to log in to our mssql servers it displays
    them.
    here is the servers I would like my code in powerscript to display
    like this. then I press the number to log me in to the server.
    I would like my search string to search for the hostname or the
    instance in the file.
    my file looks like this below too as I exported this list from my unix
    shell script.

    No. Server Hostname RDBMS
    === ====== ======== =====
    1) IBTKYPSD32A001 IBTKYPSD32A001 MSSQLServer
    2) IBTKYPSP32A017 IBTKYPSP32A017 MSSQLServer
    3) IBTKYPSP32A021 IBTKYPSP32A021 MSSQLServer
    4) IBTKYPSP32A026 IBTKYPSP32A026 MSSQLServer
    5) IBTKYPSP32A028 IBTKYPSP32A028 MSSQLServer
    6) IBTKYPSP32A031 IBTKYPSP32A031 MSSQLServer
    7) IBTKYPSP32A036HOSTED_P1 IBTKYPSP32A036 MSSQLServer
    8) IBTKYPSP32A037HOSTED_P1 IBTKYPSP32A037 MSSQLServer
    9) IBTKYPSP32A100 IBTKYPSP32A100 MSSQLServer
    10) IBTKYPSP32B017 IBTKYPSP32B017 MSSQLServer
    11) IBTKYPSP32B026 IBTKYPSP32B026 MSSQLServer
    12) IBTKYPSP32B031 IBTKYPSP32B031 MSSQLServer
    13) IBTKYPSP32B037HOSTED_P1 IBTKYPSP32B037 MSSQLServer
    14) IBTKYS9201 IBTKYS9201 MSSQLServer
    15) IBTKYSQLDEV01 IBTKYSQLDEV01 MSSQLServer

    Which server number?


      My System SpecsSystem Spec

Can anyone help problems?