Language: PowerShell
Querying SQL Servers via PowerShell
param ( [string]$server = ".", [string]$instance = $(throw "a database name is required"), [string]$query ) $connection = new-object system.data.sqlclient.sqlconnection( ` "Data Source=$server;Initial Catalog=$instance;Integrated Security=SSPI;"); $adapter = new-object system.data.sqlclient.sqldataadapter ($query, $connection) $set = new-object system.data.dataset $adapter.Fill($set) $table = new-object system.data.datatable $table = $set.Tables[0] #return table $table
Tags:
Comment:
Quick and easy way to query out information without bringing up the darned sql management tools.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search


Wouldn't call that exactly quick and easy :-}