Presentation is loading. Please wait.

Presentation is loading. Please wait.

Connect with life www.connectwithlife.co.in L.Srividya Architect Advisor | Microsoft India.

Similar presentations


Presentation on theme: "Connect with life www.connectwithlife.co.in L.Srividya Architect Advisor | Microsoft India."— Presentation transcript:

1 Connect with life www.connectwithlife.co.in L.Srividya Architect Advisor | Microsoft India

2 Agenda Brief introduction to Windows PowerShell Briefly outline the SQL Server PowerShell architecture Demo using PowerShell with SQL Server

3 Task based scripting technology that uses the.Net2.0 Framework Windows PowerShell 1.0 currently supports Windows XP SP2, Windows Server 2003, Windows Vista and Windows Server 2008. upported on multiple platforms (x86, x64 & Itanium) and by multiple language technologies (English language, Localized and Multilingual User Interface). Windows PowerShell An Introduction

4 CMDlets – Built-in commands in.NET language. Users can create their own CMDLets and use them in Powershell Functions – Functions created dynamically with PowerShell commands Scripts – text files with.PS1 files & have one or more PowerShell commands Applications – Existing Windows commands that work inside of Powershell Windows PowerShell Categories of commands

5 Windows PowerShell contd.. PowerShell.exe: shell for interactively editing and running PowerShell commands, or running.ps1 script files Core language elements, such as operators, variables, arrays, and constants Cmdlets: Commands with parameters Stop-Process –name Calc #comment – stops calc.exe Verb-Noun names: Get-Item, Set-Location Can be aliased using shorter names: gci, pa Support for file system paths Get-Help cmdlet to provide help

6 SQL Server 2008 PowerShell Leverages the power of the SQL Server management object models Not a replacement for Transact-SQL scripts, but another tool to be used for scripting SQLPS.EXE SqlServerProviderSnapin100 SqlServerCmdletSnapin100

7 SQL 2008 PowerShell in SSMS

8 SQL Server 2008 PowerShell SQLSERVER:\ drive over SMO, PBM,DC, RegisteredServers Encode-SqlNameDecode-SqlNameConvert-UrnToPath SQLSERVER:\ drive over SMO, PBM,DC, RegisteredServers Encode-SqlNameDecode-SqlNameConvert-UrnToPathInvoke-SqlcmdInvoke-PolicyEvaluationInvoke-SqlcmdInvoke-PolicyEvaluation SQLPS.exe Microsoft.SqlServer.Management.PSSnapins.dllMicrosoft.SqlServer.Management.PSProvider.dll

9 PowerShell in Agent SQL Server Agent: SQL Server PowerShell subsystem Can now create PowerShell job steps Very similar to command prompt job steps Launches sqlps.exe with an input script

10 PowerShell Providers Implement a powershell drive Navigation similar to file paths: cmdletCanonical Alias cmd AliasUNIX Shell Alias Description Get-Locationglpwd Get the current node. Set-Locationslcd, chdir Change the current node. Get-ChilditemgcidirlsList the objects stored at the current node. Get-ItemgiReturn the properties of the current node. Move-ItemmimovemvMove an object. Rename-ItemrnirnrenRename an object. Remove-Itemridel, rdrm, rmdirRemove an object.

11 SQL Server PowerShell Provider Implements a SQLSERVER: drive. The SQLSERVER: drive implements four folders to support SQL Server management object models: FolderObject Models SQLSERVER:\SQLMicrosoft.SqlServer.Management.SMO Microsoft.SqlServer.Management.SMO.Agent Microsoft.SqlServer.Management.SMO.Broker Microsoft.SqlServer.Management.SMO.Mail SQLSERVER:\SQLPolicyMicrosoft.SqlServer.Management.DMF Microsoft.SqlServer.Management.Facets SQLSERVER:\SQLRegistrationMicrosoft.SqlServer.Management.RegisteredServers SQLSERVER:\DataCollectionMicrosoft.SqlServer.Management.Collector Microsoft.SqlServer.Management.CollectorEnum

12 SQLSERVER: PowerShell Paths You already know the object hierarchy: it’s very similar to the Object Explorer tree But it is slightly different (it’s the SMO model) Navigate using the PowerShell commands and their command prompt aliases Use dir (gci) and cd (sl) to investigate the path structure At each node you can use the methods and properties of the underlying management class

13 SQLSERVER: PowerShell Paths Structure Paths follow the hierarchy of the underlying object model 1 st node: SQLSERVER:\ 2 nd node: SQL\, SQLPolicy\, SQLRegistration\, or \DataCollection 3 rd and 4 th nodes: ComputerName\InstanceName 5 th and higher nodes alternate between collection classes and object classes

14 Create a Database Using SMO Create a database in the default instance on the local computer: cd SQLSERVER:\SQL\localhost\DEFAULT\Databases $MyDBVar = New-Object Microsoft.SqlServer.Management.SMO.Database $MyDBVar.Parent = (Get-Item..) $MyDBVar.Name = “NewDB” $MyDBVar.Create() dir $MyDBVar.Drop()

15 SQL Server Identifiers SQL Server identifiers allow characters which PowerShell may try to interpret Have three ways to deal with them: Encode hex value: %28local%29 This one always works Escape with ` character: `(local`) Quote: cd “SQLSERVER:\SQL\(local)” Use Encode-Sqlname and Decode-Sqlname to encode or decode quoted identifiers.

16 Final PowerShell Reminder While you can leverage a lot of what you learned from the command prompt, you’ll need to familiarize yourself with the new environment. While PowerShell looks a lot like the command prompt environment, it’s not exactly the same. While Invoke-Sqlcmd looks a lot like sqlcmd.exe, it’s not exactly the same.

17 SQL Server PowerShell Microsoft Confidential

18 The Road Ahead Incorporate PowerShell 2.0 Incorporate the PowerShell 2.0 visual editor Add support for other SQL Server management object models Analysis Services, Reporting Services, SSIS Additional cmdlets based on customer demand and common scenarios Additional documentation

19 References SQL Server 2008 Books Online: SQL Server PowerShell Overview SQL Server PowerShell Help Learning PowerShell Books Windows PowerShell in ActionWindows PowerShell in Action by Bruce Payette Windows PowerShell Cookbook Windows PowerShell Cookbook by Lee Holmes Whitepapers Windows Powershell Website

20 Feedback / QnA Your Feedback is Important! Please take a few moments to fill out our online feedback form at: > For detailed feedback, use the form at http://www.connectwithlife.co.in/vtd/helpdesk.aspx Or email us at vtd@microsoft.com Use the Question Manager on LiveMeeting to ask your questions now!

21 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

22


Download ppt "Connect with life www.connectwithlife.co.in L.Srividya Architect Advisor | Microsoft India."

Similar presentations


Ads by Google