SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Powershell script to allow you to login to any instance or sqlserver


Powershell script to allow you to login to any instance or sqlserver

Author
Message
terryj30
terryj30
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1248 Visits: 261
Comments posted to this topic are about the item Powershell script to allow you to login to any instance or sqlserver
tedo
tedo
SSC Eights!
SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)

Group: General Forum Members
Points: 924 Visits: 523
Thank you for this PowerShell script this has helped me alot, I can quickly access any of my SQL boxes with out logging on to the gui.
Ric Sierra
Ric Sierra
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1589 Visits: 342
The good news:
PowerShell is here!Smile

The bad news:
PowerShell is here. Handle with care.Unsure
David Conn
David Conn
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3508 Visits: 1183
What is "file.txt" ?
terryj30
terryj30
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1248 Visits: 261
Hi there,

You will need to create a file called file.txt or rename file.txt to say sqlserverlist.txt or something.

Then you will need to list all your sqlservers in that file. oncee this is done run that program it will then ask you to enter a string say type in the first 3 letters of the server and press enter it will then bring you back all the servers with a simaler name then press what ever number server you want.

Regards

T
David Conn
David Conn
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3508 Visits: 1183
Thanks.

Got it working.

David
terryj30
terryj30
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1248 Visits: 261
Cool that is good, I like this program i have not seen one like it so had to write it, where i work we have around 100 sqlservers and its a pain to login to every box or through the gui sometimes so this is very quick. I hope you like the program.

Terry
Arshpreet
Arshpreet
Old Hand
Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)

Group: General Forum Members
Points: 314 Visits: 722
I am pretty much new to powershell.
I saw this script is quite useful for my environment. If someone let me know how to use this.
I tried couple of time. But everytime i ran the below script, it terminates automatically but i have the text file in D drive.

Please correct me if i am wrong...
I created a file in D:\sqlList.txt
then,
Run> Powershell> enter
PS D:\ document and setting\abc cd \
PS D:\gci
-a --- _________________
-a --- 6/21/2010 10.20am 11 sqlList.txt

#copy the code and paste it in the window via right click
PS D:\$file = get-content "sqlList.txt"

# checks file if not found then terminates

if (-not($file))
{
write-error($file+ " not found. Terminating .... ");
exit
}
# matches the string ie type in any string for yout instance

$match = $file | Select-String (Read-Host "search string")
# if the match is found then this will run the select
if ($match.count -gt 0)
{
$inst = @()
for ($i = 0; $i -lt $match.count; $i++)
{
$temp = ""
$line = $match[$i].tostring()
for ($j = $line.length-1; $j -ge 0; $j--)
{
if ($line[$j] -eq ":")
{
break
}
$temp = $line[$j] + $temp
}

$inst = $inst + $temp
write-output ("Press "+($i+1)+" for : " + $inst[$i])
}

$inp = ""
$flag = "true"
do {
$inp = read-host("Enter choice : 1 - "+$match.count)
if ($inp -lt 1 -or $inp -gt $match.count)
{
$flag = "false";
write-error ("Invalid entry. Enter between 1 - "+$match.count)
}
else {
$flag = "true";
}
} while ($flag -eq "false")

write-output ("Logging on to the SQLSERVER you requested: "+$inst[$inp-1])

if ($inst[$inp-1] -ne "") {
$inst[$inp-1] + ""; sqlcmd -S $inst[$inp-1] -E
}

}


--If i try to type all the code in powershell window then at the end how to execute this code...

I think i am doing some silly mistake, but please help me to get it over...

Thanks in advance....

A Singh
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search