Download presentation
Presentation is loading. Please wait.
Published byEvan Little Modified over 8 years ago
1
Introduction to SQL Server Automation with Powershell by Chris Sommer
2
Agenda Introduction Automation The PowerShell Language The SQL Server Module (SQLPS) Demos
3
Introduction
4
Chris Sommer SQL Server DBA at Paychex @cjsommer on Twitter Email: cjsommer@gmail.comcjsommer@gmail.com Blog: www.cjsommer.comwww.cjsommer.com LinkedIn: www.linkedin.com/in/cjsommer/www.linkedin.com/in/cjsommer/
5
Automation
6
What is automation? Automation is having computers perform repetitive tasks for us.
7
What problems does automation solve? The people problem! Automation brings Repeatability Consistency Reliability Scalability
8
What do I get out of automation? I don’t have to perform the mundane and repetitive tasks any more. It frees up my time so I can work on the fun stuff and learn new things. I allows me to sleep at night and gives me a sense of relief. I can look like a rockstar!
9
The PowerShell Language
10
PowerShell Programming Constructs Variables Conditional Statements Loops Functions Built-in Error Handling Modules
11
Variables Variables are a reference to data or information Supports your standard data types Identified by a leading “$” character Not a strongly typed language Special variables
12
Custom Objects Custom objects are a collection of related data Makes it easy to pass related data in a script Referenced similarly to a variable
13
Conditionals Check if a statement is true or false Comparison operators -eq -ne -gt- ge -lt -le -like -match -contains -and -or
14
Loops Allow us to repeat a block of code until a condition is met while do while do until for foreach
15
Functions Functions bring reusability to a script Functions should do 1 thing and do it well Functions return all output to the caller
16
Error Handling Not all errors are terminating Can control ErrorAction at many levels Script, Function, Cmdlet Try/Catch/Finally Exit codes
17
Modules Modules are collections of related cmdlets, providers, functions, variables, aliases. Module types Script Binary Manifest Dynamic Built-In, Custom and Vendor Modules
18
SQL Server Module (SQLPS)
19
What does SQLPS Include? The SQLSERVER provider SQL Management Object Libraries (SMO) 34 SQL Server Cmdlets
20
SQLSERVER: Provider Browse SQL Server like a directory structure Used in conjunction with SMO Used with Cmdlets
21
SQL Management Objects (SMO) SMO allows you to manage SQL Server SQL Instance settings Database settings and configuration Perform DDL tasks on databases Script database objects Manage SQL Agent jobs
22
SQL Server Cmdlets Cmdlets provide functionality to perform a number of SQL Server tasks. Invoke-Sqlcmd Backup-SqlDatabase Restore-SqlDatabase Manage AlwaysOn Availability Groups
23
Demos
24
Questions?
25
Image Credits http://remarcom.typepad.com/remarkable_communication/2007/10/what-problem-ar.html http://blog.al.com/techcetera/2008/08/review_guitar_hero_aerosmith.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.