The Multifunctioning DBA

Jan 15 2012   8:00AM GMT

Connect-sql Function

Colin Smith Colin Smith Profile: Colin Smith

This is a function that I keep in my profile so I can call it in any of my scripts that will run from my profile. It makes it easier for me so it might for you.

function connect-sql ($arg)
if($arg -eq $null)
$server = Read-Host “enter instance name to connect to”
$server = $arg
$global:s = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) $server


This function allows you to make SMO connections to your instances very easily. You can pass it the instance name or it will ask you if you do not. Hope that helps

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: