Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
SQL Server
»
Connect-MSSQL-IPWindowsAuth
Connect-MSSQL-IPWindowsAuth
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Access
AD
ADO
Analysis Server
Attributes
Backup
CheckDB
Connect
Connection String
Create database
Create table
CSV
Database
Port
PowerShell
Properties
Service
SMO
SQL
SQL Authentication
SQL Server
stop jobs
test-connection
Windows Authentication
WMI
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
Richard Giles
10-06-2008
Downloads: 504
File size: 2.3kB
Views: 1,825
Embed
Connect-MSSQL-IPWindowsAuth
## =====================================================================
## Title
: Connect-MSSQL-IPWindowsAuth
## Description : Connect to SQL Server using IP address, instance and
##
Windows authentication
## Author
: Idera
## Date
: 9/1/2008
## Input
: -ipAddress < xxx.xxx.xxx.xxx | xxx.xxx.xxx.xxx\instance >
##
-verbose
##
-debug
## Output
: Database names and owners
## Usage
: PS> . Connect-MSSQL-IPWindowsAuth -ipAddress 127.0.0.1 -v -d
## Notes
:
##
Tag
: MSSQL, connect, IP, Windows Authentication
## Change Log
:
## =====================================================================
param
(
[
string
]
$ipAddress
=
"127.0.0.1"
,
[
switch
]
$verbose
,
[
switch
]
$debug
)
function
main()
{
if
(
$verbose
) {
$VerbosePreference
=
"Continue"
}
if
(
$debug
) {
$DebugPreference
=
"Continue"
}
Connect-MSSQL
-IPWindowsAuth
$ipAddress
}
function
Connect-MSSQL
-IPWindowsAuth
(
$ipAddress
)
{
trap
[
Exception
]
{
write-error
$
(
"TRAPPED: "
+
$_
.
Exception.Message
);
continue
;
}
# Load-SMO assemblies
[
void
][
System.Reflection.Assembly
]::
LoadWithPartialName
(
"Microsoft.SqlServer.Smo"
)
[
void
][
System.Reflection.Assembly
]::
LoadWithPartialName
(
"Microsoft.SqlServer.SqlEnum"
)
[
void
][
System.Reflection.Assembly
]::
LoadWithPartialName
(
"Microsoft.SqlServer.SmoEnum"
)
[
void
][
System.Reflection.Assembly
]::
LoadWithPartialName
(
"Microsoft.SqlServer.ConnectionInfo"
)
# Instantiate a server object
# TIP: using PowerShell "`" to signify line continuation
Write-Debug
"Creating SMO Server object..."
$smoServer
=
New-Object
-typename
Microsoft.SqlServer.Management.Smo.Server
`
-argumentlist
"$ipAddress"
# Use Windows Authentication by setting LoginSecure to TRUE
Write-Debug
"Setting Windows Authentication mode..."
$smoServer
.
ConnectionContext.set_LoginSecure
(
$TRUE
)
# Clear the screen
# TIP: cls will clear the PowerShell console
cls
Write-Host
Your connection
string
contains these values:
Write-Host
$smoServer
.
ConnectionContext.ConnectionString.Split
(
";"
)
Write-Host
# List information about the databases
Write-Host
"Databases on "
$ipAddress
Write-Host
foreach
(
$db
in
$smoServer
.
Databases
)
{
write-host
"Database Name : "
$db
.
Name
write-host
"Owner
: "
$db
.
Owner
write-host
}
}
main
Filed under:
SQL Server
,
Connect
,
SMO
,
Windows Authentication
Connect to SQL Server using IP address, instance and Windows authentication.
Copyright 2011 PowerShell.com. All rights reserved.