Skip to content

Instantly share code, notes, and snippets.

@RichieBzzzt
Last active July 13, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichieBzzzt/9a5ea6280d37b850011bb3996426a534 to your computer and use it in GitHub Desktop.
Save RichieBzzzt/9a5ea6280d37b850011bb3996426a534 to your computer and use it in GitHub Desktop.
cls
Set-Location "/home/<whatisyourlinuxuser>/sqltoolservice/"
$Assem = (
"Microsoft.SqlServer.Management.Sdk.Sfc",
"Microsoft.SqlServer.Smo",
"Microsoft.SqlServer.ConnectionInfo"
);
Add-Type -AssemblyName $Assem
Function Connect-SqlConnection {
[CmdletBinding()]
param
(
$instance,
$uname,
$pword
)
$sqlConnection = new-object Microsoft.SqlServer.Management.Common.SqlConnectionInfo($instance, $uname, $pword)
try {
$SqlSvr = New-Object Microsoft.SqlServer.Management.Smo.Server($SqlConnection)
return $SqlSvr
}
catch {
throw $_.Exception.InnerException.ToString()
}
}
$thisInstance = "localhost"
$thisUname = "sa"
$thisPword = "<WhatIsYourPassword>"
$thisSqlConn = Connect-SqlConnection -Instance $ThisInstance -Uname $thisUName -Pword $thisPword
foreach ($db in $thisSqlConn.Databases)
{
Write-Verbose $db.Name -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment