Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Hi there I am trying to write a powershell scrip so I can connect tomy mssql servers via osql

Reply
 
Old 07-30-2008   #1 (permalink)
ted


 
 

Hi there I am trying to write a powershell scrip so I can connect tomy mssql servers via osql

However, I do not want to type all off the sqlserver instance I would
like to grep from a file say part of the instance name and I would
like it to come back to me with say a count and i can then just press
1 2 or 3 and then it will log me on. I have tried a number of ways to
do this to no avail.

Please help kind regards in advance heres my code.

function usage
{
print "

Usage:

$0 search_string

Where

search_string is to be found in dataserver or hostnames

";
}

$usage = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
#--
#-- Takes one argument, a string to search for in the server or host
name
#--
#--

prog_name=`sqlcmd`
find_this=$1

#--

#-- If no argument given then bail out, dont see the point of listing
every host.
#-- If user really wants to do that then they can supply % as an
argument
#--
#--

if ( -notmatch $find_this "")


#--
#-- count is used as in index into an array we are creating
#--
#--
#$count = 0

#--
#-- print a nice header
#--
#--


# while ($ANS -eq "")
# do
#{#--
#-- Read in all the servers and necessary info
#--
#--
#let count=count+1
#printf "%-4s %-20s\t%-20s\t%s\n" "${count})" $serv $host $prod
#server[$count]=$serv
#host[$count]=$host
#prod[$count]=$prod
#ipad[$count]=$ip
#loginname[$count]=$login
#}
#until

#--
#-- Sit in a loop and pester user for a sensible number
#-- When we get one we will either ssh or sqsh to the host
#-- Change the title in the xterm on connecting and change it back
afterwards
#--
#--
#$ANS=""
if ( -eq $ANS "" )
do
print
print -n "Which server number? "
read ANS

if [[ $ANS != [0-9]* ]];
write-host "Please enter a number from the list"
ANS=""
continue
elseif [[ $ANS -lt 1 ]] || [[ $ANS -gt $count ]]
{
write-host "Please enter a number between 1 and $count"
ANS=""
continue }
else
case $prog_name
{write-host "Connecting to $s $a")
$a = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
{$ANS+ ""; sqlcmd -S $a -E}

echo "Hostname"
end















My System SpecsSystem Spec
Old 07-30-2008   #2 (permalink)
ted


 
 

Hi there I am trying to write a powershell scrip so I can connect tomy mssql servers via osql

However, I do not want to type all off the sqlserver instance I would
like to grep from a file say part of the instance name and I would
like it to come back to me with say a count and i can then just press
1 2 or 3 and then it will log me on. I have tried a number of ways to
do this to no avail.

Please help kind regards in advance heres my code.

function usage
{
print "

Usage:

$0 search_string

Where

search_string is to be found in dataserver or hostnames

";
}

$usage = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
#--
#-- Takes one argument, a string to search for in the server or host
name
#--
#--

prog_name=`sqlcmd`
find_this=$1

#--

#-- If no argument given then bail out, dont see the point of listing
every host.
#-- If user really wants to do that then they can supply % as an
argument
#--
#--

if ( -notmatch $find_this "")


#--
#-- count is used as in index into an array we are creating
#--
#--
#$count = 0

#--
#-- print a nice header
#--
#--


# while ($ANS -eq "")
# do
#{#--
#-- Read in all the servers and necessary info
#--
#--
#let count=count+1
#printf "%-4s %-20s\t%-20s\t%s\n" "${count})" $serv $host $prod
#server[$count]=$serv
#host[$count]=$host
#prod[$count]=$prod
#ipad[$count]=$ip
#loginname[$count]=$login
#}
#until

#--
#-- Sit in a loop and pester user for a sensible number
#-- When we get one we will either ssh or sqsh to the host
#-- Change the title in the xterm on connecting and change it back
afterwards
#--
#--
#$ANS=""
if ( -eq $ANS "" )
do
print
print -n "Which server number? "
read ANS

if [[ $ANS != [0-9]* ]];
write-host "Please enter a number from the list"
ANS=""
continue
elseif [[ $ANS -lt 1 ]] || [[ $ANS -gt $count ]]
{
write-host "Please enter a number between 1 and $count"
ANS=""
continue }
else
case $prog_name
{write-host "Connecting to $s $a")
$a = get-content "C:\CheckSQLServer\sql\SQLTokyo.txt"
{$ANS+ ""; sqlcmd -S $a -E}

echo "Hostname"
end














My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to get powershell to write to event log or write a log file? PowerShell
Re: HowTo: Install missing hardware drivers using powershell scrip PowerShell
ways to connect to MSSQL 2000 sever via vbscript VB Script
Unable to connect to outside servers System Security
Find & Replace in MSSQL Tables through PowerShell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46