![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 -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 Specs![]() |
| | #2 (permalink) |
| | 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 -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 Specs![]() |
![]() |
| 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 | |||