SQL Server & PowerShell

Slides:



Advertisements
Similar presentations
Burt King We will cover: Essentials --No command line needed here (mott) What is SQL Server How does it come to life What are the.
Advertisements

Week 6: Chapter 6 Agenda Automation of SQL Server tasks using: SQL Server Agent Scheduling Scripting Technologies.
MCTS GUIDE TO MICROSOFT WINDOWS 7 Chapter 10 Performance Tuning.
James Boother Blog: INTRODUCTION TO POWERSHELL.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 11: Monitoring Server Performance.
Gather SQL Server Performance Data with PowerShell
MCTS Guide to Microsoft Windows Server 2008 Network Infrastructure Configuration Chapter 11 Managing and Monitoring a Windows Server 2008 Network.
Welcome Course 20410B Module 0: Introduction Audience
Module 2: Planning to Install SQL Server. Overview Hardware Installation Considerations SQL Server 2000 Editions Software Installation Considerations.
Module 3: SQL Server 2005 Administrative Tools. Overview Using SQL Server Management Studio Using SQL Computer Manager Using the sqlcmd Utility Using.
11 MAINTAINING THE OPERATING SYSTEM Chapter 5. Chapter 5: MAINTAINING THE OPERATING SYSTEM2 CHAPTER OVERVIEW Understand the difference between service.
11 MAINTAINING THE OPERATING SYSTEM Chapter 5. Chapter 5: MAINTAINING THE OPERATING SYSTEM2 CHAPTER OVERVIEW  Understand the difference between service.
Module 2: Using Transact-SQL Querying Tools. Overview SQL Query Analyzer Using the Object Browser Tool in SQL Query Analyzer Using Templates in SQL Query.
MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443) Chapter 1: Designing the Hardware and Software.
Chapter 17: Watching Your System BAI617. Chapter Topics Working With Event Viewer Performance Monitor Resource Monitor.
Module 1: Introduction to Microsoft SQL Server 7.0.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 3 Administration of Users.
MCTS Guide to Microsoft Windows 7
Microsoft ® Official Course Module XA Using Windows PowerShell ®
SharePoint 2010 Development Environment A Guide to Setup SharePoint 2010 Development Environment on Windows 7 Machine.
PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.
Appendix A Starting Out with Windows PowerShell™ 2.0.
Module 7: Fundamentals of Administering Windows Server 2008.
ORACLE
Learningcomputer.com SQL Server 2008 Configuration Manager.
Chokchai Junchey Microsoft Product Specialist Certified Technical Training Center.
Learningcomputer.com SQL Server 2008 – Administration, Maintenance and Job Automation.
Introduction to Windows PowerShell DANIEL HIBBERT PRIMER FIELD ENGINEER DMVMUG User Conference 2013 – Reston, VA.
Module 4 : Installation Jong S. Bok
POWERSHELL SHENANIGANS KIERAN JACOBSEN HP ENTERPRISE SERVICES.
Module 5: Upgrading to SQL Server 7.0. Overview Planning an Upgrade Preparing to Upgrade Verifying the Upgrade Setting a Compatibility Level.
1 Chapter Overview Performing Configuration Tasks Setting Up Additional Features Performing Maintenance Tasks.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 11: Monitoring Server Performance.
SQL Server 2000 Sys Admin Jeremiah Curtis Engineering Services
Module 10: Preparing to Monitor Server Performance.
1 Chapter Overview Planning to Install SQL Server 2000 Deciding SQL Server 2000 Setup Configuration Options Running the SQL Server 2000 Setup Program Using.
Module 1 Introduction to SQL Server® 2008 R2 and its Toolset.
MISSION CRITICAL COMPUTING Siebel Database Considerations.
 It is Microsoft's new task-based command- line shell and scripting language designed especially for system administration.  It helps Information Technology.
Module 6: Administering Reporting Services. Overview Server Administration Performance and Reliability Monitoring Database Administration Security Administration.
1 Chapter Overview Monitoring Access to Shared Folders Creating and Sharing Local and Remote Folders Monitoring Network Users Using Offline Folders and.
Windows Certification Paths OR MCSA Windows Server 2012 Installing and Configuring Windows Server 2012 Exam (20410) Administering Windows Server.
Configuring SQL Server for a successful SharePoint Server Deployment Haaron Gonzalez Solution Architect & Consultant Microsoft MVP SharePoint Server
Managing Server 2012 Lecture 3 Lecturer: Dr. Simon Tran Course: IT 442.
SQL Database Management
Start-SPPowerShell – Introduction to PowerShell for SharePoint Admins and Developers Paul BAker.
Smarter Technology for Better Business
How to convert a Demo to Multi-user
Module 9: Preparing to Administer a Server
Preparing for the Windows 8.1 MCSA
Working with SQL Server for Linux Cross-Platform
Module Overview Installing and Configuring a Network Policy Server
Introduction to PowerShell
MCTS Guide to Microsoft Windows 7
SQL Server Monitoring Overview
Deploying and Configuring SSIS Packages
Contained DB? Did it do something wrong?
Getting Started with the Data ONTAP PowerShell Toolkit
SharePoint Saturday Omaha April 2016
Use PowerShell & dbatools to Manage your SQL Server Environment
dbatools - PowerShell and SQL Server Working Together
Getting started with Powershell for the DBA
Read-Only Domain Controllers (RODCs)
Mass Hunting and exploitation with powershell
Gold Sponsors.
ZORAN BARAC DATA ARCHITECT at CIN7
SharePoint 2013 Best Practices
The DBA Quit and now you’re it:
Gordon McKenna | MVP & CEO | Inframon
Presentation transcript:

SQL Server & PowerShell Marek Chmel MVP: Data Platform | MCSE: Data Management and Analytics | MCT: Regional Lead | CEH v8 marek.chmel@technet.ms @marekchmel

Motivation Why Use PowerShell to Manage SQL Server Lightweight Access to Server Management Repeatable Management through Scripting Access both Windows and SQL Server Properties “PowerShell is a Core IT Skill – Learn it or be Left Behind” Basics of using PowerShell with SQL Server Use of the SQL Server Provider Using SMO (SQL Management Objects)

Environment & Security Command Line Tab completion auto completes commands, etc. Get-History returns previously run commands Up/Down arrows scrolls through previously run commands Integrated Scripting Environment – ISE (PS 2.0+) Scripts allow you to batch commands together You must include the path to the script to run it By requiring the path, prevents scripts from “hijacking” operating system commands By default you cannot run scripts Set-ExecutionPolicy set by default to Restricted Change to RemoteSigned to run local scripts NOT the case for sqlps.exe, though

PowerShell Language PowerShell is an Object-Based Language Not Object-Oriented Cmdlets are Command-Line Utilities built into PowerShell They use a Verb-Noun Naming Convention Get-Process Stop-Service Three most important cmdlets Get-Help Get-Command Get-Member

SQL Server & PowerShell options SMO SMO: SQL Management Objects .Net Libraries Contain Objects for SQL Server [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "SqlServer" } | Select-Object FullName

SQL Provider PowerShell Module CmdLets for SQL Server Navigable tree Types, Formats Get-Command -CommandType Cmdlet –Module SQLPS,SQLASCMDLETS | Select-Object Name, Module | Sort-Object Module, Name | Format-Table -AutoSize

DEMOS

WMI Service Types SqlServiceType Description 1 SQL Server Service 2 SQL Server Agent Service 3 Full-Text Search Engine Service 4 Integration Services Service 5 Analysis Services Service 6 Reporting Services Service 7 SQL Browser Service

Main SMO Objects Server Property Description Information This includes nonconfigurable instance settings, such as BuildNumber, Edition, OSVersion, and ProductLevel. This also includes settings specified during install, for example, Collation, MasterDBPath, and MasterDBLogPath. Settings This lists some instance level configurable settings, such as LoginMode and BackupDirectory. UserOptions This has options that can be set for user connections, such as AnsiWarnings, AnsiNulls, AnsiPadding, and NoCount. Configuration This contains instance-specific settings such as AgentXPs, remote access, clr enabled, and xp_cmdshell, which you will normally see and set when you use the sp_configure system stored procedure.

Configuration with PowerShell Depending on what server properties you need to change, you may need to determine which of the following classes you may need to access: Settings, UserOptions, or Configuration. Once you have determined which class and property you want to change, you can change the values and invoke the Alter() method:

Why Maintain a Server Inventory Need an overview of your Domain Allows you to identify outliers You can see resource usage How much are you using now? What's the growth rate? Reports help you justify new resources

What Data Do You Collect? Computer Name, Domain, Make, Model Operating System Versions and Patch Levels Total Physical Memory Local Disk (SAN storage is local) SQL Server Instance Information Version, Edition, Service Pack Default Data, Log, Backup Location Configuration Options Databases with files and sizes Logins and Users

A Little Bit about WMI WMI - Windows Management Instrumentation Provides Access to All Windows System Information Information Grouped into Classes Win32_ComputerSystem provides computer name and model, number of processors, etc. Win32_OperatingSystem provides OS type, service pack installed, etc. Win32_PhysicalMemory provides physical memory device, and capacity, etc. Win32_LogicalDisk provides local storage size, free space, etc.

Getting WMI Data PowerShell V2 and V1 – Get-WMIObject PowerShell V3+ – Get-CimInstance Get-WMIObject is Deprecated Uses remote procedure calls (RPCs) Can cause problems with access, firewall issues Get-CimInstance uses WinRM

Capture Performance Baseline Baseline shows normal performance Deviations from Baseline require investigation Frequency of Data Capture is important Too often impacts performance Too seldom can miss important events Balance comes with experience

Scripting the Data Capture Capture the counter data # Initialize Perfcounters $ppt = new-object System.Diagnostics.PerformanceCounter $ppt.CategoryName = 'Processor' $ppt.CounterName = '% Processor Time' $ppt.InstanceName = '_Total' $pptv = $ppt.nextvalue() Insert into Performance Database Wait defined interval and do it again

Q&A Marek Chmel MVP: Data Platform | MCSE: Data Management and Analytics | MCT: Regional Lead | CEH v8 marek.chmel@technet.ms @marekchmel