PacktLib: SQL Server 2012 with PowerShell V3 Cookbook

SQL Server 2012 with PowerShell V3 Cookbook

Credits

About the Author

Acknowledgement

About the Reviewers

www.PacktPub.com

Preface

Getting Started with SQL Server and PowerShell

Introduction

Before you start: Working with SQL Server and PowerShell

Working with the sample code

Exploring the SQL Server PowerShell hierarchy

Installing SMO

Loading SMO assemblies

Discovering SQL-related cmdlets and modules

Creating a SQL Server instance object

Exploring SMO server objects

SQL Server and PowerShell Basic Tasks

Introduction

Listing SQL Server instances

Discovering SQL Server services

Starting/stopping SQL Server services

Listing SQL Server configuration settings

Changing SQL Server instance configurations

Searching for database objects

Creating a database

Altering database properties

Dropping a database

Changing a database owner

Creating a table

Creating a view

Creating a stored procedure

Creating a trigger

Creating an index

Executing a query / SQL script

Performing bulk export using Invoke-Sqlcmd

Performing bulk export using bcp

Performing bulk import using BULK INSERT

Performing bulk import using bcp

Basic Administration

Introduction

Creating a SQL Server instance inventory

Creating a SQL Server database inventory

Listing installed hotfixes and service packs

Listing running/blocking processes

Killing a blocking process

Checking disk space usage

Setting up WMI Server event alerts

Detaching a database

Attaching a database

Copying a database

Executing a SQL query to multiple servers

Creating a filegroup

Adding secondary data files to a filegroup

Moving an index to a different filegroup

Checking index fragmentation

Reorganizing/rebuilding an index

Running DBCC commands

Setting up Database Mail

Listing SQL Server jobs

Adding a SQL Server operator

Creating a SQL Server job

Adding a SQL Server event alert

Running a SQL Server job

Scheduling a SQL Server job

Security

Introduction

Listing SQL Server service accounts

Changing SQL Server service account

Listing authentication modes

Changing authentication mode

Listing SQL Server log errors

Listing failed login attempts

Listing logins, users, and database mappings

Listing login/user roles and permissions

Creating a login

Assigning permissions and roles to a login

Creating a database user

Assigning permissions to a database user

Creating a database role

Fixing orphaned users

Creating a credential

Creating a proxy

Advanced Administration

Introduction

Listing facets and facet properties

Listing policies

Exporting a policy

Importing a policy

Creating a condition

Creating a policy

Evaluating a policy

Enabling/disabling change tracking

Running and saving a profiler trace event

Extracting the contents of a trace file

Creating a database master key

Creating a certificate

Creating symmetric and asymmetric keys

Setting up Transparent Data Encryption (TDE)

Backup and Restore

Introduction

Changing database recovery model

Listing backup history

Creating a backup device

Listing backup header and file list information

Creating a full backup

Creating a backup on mirrored media sets

Creating a differential backup

Creating a transaction log backup

Creating a filegroup backup

Restoring a database to a point in time

Performing an online piecemeal restore

SQL Server Development

Introduction

Inserting XML into SQL Server

Extracting XML from SQL Server

Creating an RSS feed from SQL Server content

Applying XSL to an RSS feed

Storing binary data into SQL Server

Extracting binary data from SQL Server

Creating a new assembly

Listing user-defined assemblies

Extracting user-defined assemblies

Business Intelligence

Introduction

Listing items in your SSRS Report Server

Listing SSRS report properties

Using ReportViewer to view your SSRS report

Downloading an SSRS report in Excel and PDF

Creating an SSRS folder

Creating an SSRS data source

Changing an SSRS report's data source reference

Uploading an SSRS report to Report Manager

Downloading all SSRS report RDL files

Adding a user with a role to an SSRS report

Creating folders in an SSIS package store and MSDB

Deploying an SSIS package to the package store

Executing an SSIS package stored in the package store or File System

Downloading an SSIS package to a file

Creating an SSISDB catalog

Creating an SSISDB folder

Deploying an ISPAC file to SSISDB

Executing an SSIS package stored in SSISDB

Listing SSAS cmdlets

Listing SSAS instance properties

Backing up an SSAS database

Restoring an SSAS database

Processing an SSAS cube

Helpful PowerShell Snippets

Introduction

Documenting PowerShell script for Get-Help

Getting a timestamp

Getting additional error messages

Listing processes

Getting aliases

Exporting to CSV and XML

Using Invoke-Expression

Testing regular expressions

Managing folders

Manipulating files

Searching for files

Reading an event log

Sending e-mail

Embedding C# code

Creating an HTML report

Parsing XML

Extracting data from a web service

Using PowerShell Remoting

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

SQL Server and PowerShell CheatSheet

PowerShell Primer

PowerShell Primer

PowerShell Primer

PowerShell Primer

PowerShell Primer

PowerShell Primer

PowerShell Primer

PowerShell Primer

PowerShell Primer

Resources

Resources

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Creating a SQL Server VM

Index