Wednesday, October 12, 2011

Connecting to SQL Databases in Powershell

SQLPS is a utility that creates a Windows PowerShell environment and then loads and registers the SQL Server snap-ins. You can use sqlps to:

- Interactively run Windows PowerShell commands.
- Run Windows PowerShell script files.
- Run SQL Server cmdlets.

How do you use it? Simple.
1. Open Powershell
2. Type sqlps
3. Type dir and SQL Server provider paths to navigate through the hierarchy of SQL Server objects.






















By default, sqlps runs with the scripting execution policy set to Restricted, which prevents running any Windows PowerShell scripts. You can use the Set-ExecutionPolicy cmdlet to enable running signed scripts, or any scripts. Only run scripts from trusted sources, and secure all input and output files using the appropriate NTFS permissions. For more information about enabling Windows PowerShell scripts, see Running Windows PowerShell Scripts.


For a detailed microsoft explaination go here
http://msdn.microsoft.com/en-us/library/cc281962.aspx

Don't forget the Encoding / Unicode / Character Sets

Today, working with heterogeneous systems is a must and yet too many developers have forgotten more (or more honestly never knew) about Unicode, Characters Sets and encoding than is safe/recommended/sensible.
To that end I'd wanted to write an article on the subject but found one that does it better that i ever could.
This is a highly recommended read for any/every developer.
ww.joelonsoftware.com/articles/Unicode.html