INTRODUCTION TO POWERSHELL Martin Bell SQL Server MVP

INTRODUCTION TO POWERSHELL Martin Bell SQL Server MVP Email: Martin. Bell@BTInternet. com Blog: http: //sqlblogcasts. com/blogs/martinbell/

� Windows Power. Shell is a powerful scripting shell � The Windows Power. Shell language supports more complex logic than Transact-SQL scripts

� The SQL Server provider enables a simple navigation mechanism similar to file system paths � A set of SQL Server cmdlets � SQLPS is a closed mini-shell

� The sqlps utility that is used to run Windows Power. Shell sessions that include the SQL Server snap-ins

cmdlet Canonical cmd alias UNIX shell alias Description Get-Location gl pwd Gets the current node. Set-Location sl cd, chdir Changes the current node. Get-Child. Item gci dir ls Lists the objects stored at the current node. Get-Item gi Move-Item mi move mv Moves an object. Rename-Item rni rn ren Renames an object. Remove-Item ri del, rd rm, rmdir Removes an object. Returns the properties of the current item.

cmdlet Description Runs a script containing the languages and commands supported by the SQL Server sqlcmd utility i. e. T-SQL or XQuery syntax. Invoke-Policy. Evaluation applies/reconfigures policy-based Policy. Evaluation management policies. Invoke-Sqlcmd Encode-Sql. Name Reformats a SQL Server identifier into a representation that will work in Windows Power. Shell. Decode-Sql. Name Converts an encoded SQL Server identifier back to the original identifier. Convert. Urn. To. Path Converts SMO URN strings to a Windows Power. Shell path.

� For SQLPS install the SQL Server 2008 client components to run SQL Server features for Windows Power. Shell � The SQL Server provider for Windows Power. Shell can connect to instances of SQL Server 2008, SQL Server 2005 (SP 2 or later), or SQL Server 2000 (SP 4). � Some functionality is limited on SQL Server 2005 and SQL Server 2000

� Manage SQL Server instances �Manage � Manage Databases �Backup, � Manage Policies, Start Services. . . Create, Change Delete. . . Jobs � Use SMO, WMI. . .

� Finding your way around SQLPS

� Quest- Power. GUI and Scripts http: //www. quest. com/powershell/ � Idera – Free Powershell Scripts www. idera. com/Products/Free. Tools/Power. Shell-scripts/ � SQLPSX - http: //sqlpsx. codeplex. com/ � SQL Server Books Online http: //go. microsoft. com/fwlink/? Link. Id=115 604 � Powershell Owners Manual http: //www. microsoft. com/technet/scriptce nter/topics/winpsh/manual/start. mspx

� Martin Bell’s Blog http: //sqlblogcasts. com/blogs/martinbell/ � Bill Ramos’ Blog http: //blogs. msdn. com/billramo/default. aspx � Carpe Datum – Buck Woody’s Blog http: //blogs. msdn. com/buckwoody/ � Allen White’s Blog http: //sqlblog. com/blogs/allen_white � Michiel Wories Web. Log – http: //blogs. msdn. com/mwories/default. aspx � And…
- Slides: 11