Introduction to PowerShell

Slides:



Advertisements
Similar presentations
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Advertisements

CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
en-us/sharepoint/fp
Microsoft PowerShell Tom Roeder CS fa. Motivation.NET as a platform shell web server database access Native access to resources eaiser to manage.
James Boother Blog: INTRODUCTION TO POWERSHELL.
James Boother Blog: AUTOMATING ADMIN TASKS WITH POWERSHELL.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows.
Introduction to ColdFusion By Tom Dubeck. Overview What is ColdFusion? How does it compare to other scripts? Some example code. Why you might want to.
Queries and query design What are queries? Questions that can be asked of the data in the tables. Questions can draw on one or more tables and can have.
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.
Flow of Control MINS298c Fall 1998 Chapter 9. Overview ABAP Programming Structures for: –Iteration –Decisions Control Flow –If … Then –Do & While loops.
Further Shell Scripting Michael Griffiths Corporate Information and Computing Services The University of Sheffield
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Lab 8 Shell Script Reference:
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Practical Extraction & Report Language PERL Joseph Beltran.
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
Microsoft ® Official Course Module XA Using Windows PowerShell ®
Shell Scripting Todd Kelley CST8207 – Todd Kelley1.
CMPSC 60: Week 6 Discussion Originally Created By: Jason Wither Updated and Modified By: Ryan Dixon University of California Santa Barbara.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Introducing System Managers to Win32 Perl Programming Tim Christian College of Arts and Sciences Computing Support Services.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Shell Script2 Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
 It is Microsoft's new task-based command- line shell and scripting language designed especially for system administration.  It helps Information Technology.
Windows PowerShell. What is Windows PowerShell? A command-line interface (CLI) A new way of developing Windows and other products to be more manageable.
Sed. Class Issues vSphere Issues – root only until lab 3.
Lab 8 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
Introduction to SQL Server Automation with Powershell by Chris Sommer.
Ravikanth C.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
The full name of PERL is Practical extraction and report language. It is similar to shell script and lot easier & powerful language. Perl is free to download.
Start-SPPowerShell – Introduction to PowerShell for SharePoint Admins and Developers Paul BAker.
Building Powerful Workflow Automation with Cherwell and PowerShell
Justin Randall SQLintersection Session: Friday, 10:00am-11:15pm Automating SQL Server Administration Using SQLCMD Justin Randall.
CSC 352– Unix Programming, Spring 2016, Final Exam Guide
Achieve more in less time using the new SQL PowerShell
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
PowerShell is Happening FOR REAL THIS TIME!!!
ConfigMgr Compliance Settings - Basics of Custom CIS
SQL Server & PowerShell
Getting Started with the Data ONTAP PowerShell Toolkit
Introduction to PowerShell
Azure Automation and Logic Apps:
SharePoint Saturday Omaha April 2016
Perl for Bioinformatics
PowerShell for Data Professionals
Subsetting Rows with the WHERE clause
Getting started with Powershell for the DBA
Control Structures: for & while Loops
PowerShell Best Practices for SQL DBA’s
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
Use PowerShell & dbatools to Manage your SQL Server Environment
Tech Ed North America /27/ :04 AM Required Slide
The Selection Structure
Perl Programming Dr Claire Lambert
INTRODUCTION to PERL PART 1.
Discovering the full power of parameters in Power BI
Karan Thaker CS 265 Section 001
Presentation transcript:

Introduction to PowerShell Focused on SQL Server Piotr Palka

Basics of PowerShell Scripting language Command line interpreter Object oriented (not text based) “Cmdlet”: Verb – noun –parameter Get-Process Get-Help

Enable SQL Server integration Start “PowerShell ISE” Set-ExecutionPolicy -ExecutionPolicy RemoteSigned Requires local admin priviledges Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force No special privileges needed Import-Module SqlServer

Variables Sample script: Special variables $varDate = Get-Date $var1 "***************************" "Day of the year : " + $varDate.DayOfYear $varDate.AddDays(4) Special variables $_ - The current pipeline object $Args – parameters for current function call $Error – last error

Comparison Operators 5 > 3 is not comparison in PowerShell!!!!!!! if ( 5 > 3 ) { "T" } else { "F" } Result: F What happened?

Comparison Operators Use instead: if ( 5 -ge 3 ) { "T" } else { "F" } -eq Equal -ne Not equal -ge Greater than or equal -gt Greater than -lt Less than -le Less than or equal And many more…

Logical operators -and Logical And -or Logical Or -not logical not if (( 5 -ge 3 ) -and (5 -eq 4)) { "T" } else { "F" }

Basic queries Invoke-Sqlcmd -ServerInstance . -Database TestDB1 -Query "select GetDate()" Demo – accessing query results

Iterations ForEach Collections can be created as: Performs an operation against each item in a collection Collections can be created as: Hardcoded list (in a script), e.g. list of server names Loaded from SQL query Loaded from file ForEach can be used to run scripts on multiple servers/DBs Demo

Monitoring and mass actions For Each database: SELECT physical_name, state, state_desc, size, max_size, growth FROM sys.database_files If file meets logical condition do something: if ($f.size -ge 2000) { Backup file } We can use best of scripting language and SQL

Scheduling

Questions?