© 2010 Quest Software, Inc. ALL RIGHTS RESERVED Techstravaganza 2010 PowerShell 101 Dmitry Kagansky Solutions Architect - Quest Software (Public Sector)

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Overview and Demonstration of declarative workflows in SharePoint using Microsoft SharePoint Designer 2007 Kevin Hughes MCT, MCITP, MCSA, MCTS, MCP, Network+,
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Getting Started with VMware PowerCLI Jake Robinson, Systems Engineer Bluelock 1.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Microsoft PowerShell Tom Roeder CS fa. Motivation.NET as a platform shell web server database access Native access to resources eaiser to manage.
© 2010 Quest Software, Inc. ALL RIGHTS RESERVED Techstravaganza 2010 PowerShell AD commandlets Barry Gerdsen Solutions Architect - Quest Software
Windows Server “Longhorn” RDP Airlift. Managing AD with PowerShell; Creating custom administrative consoles Dmitry Sotnikov CTO, Windows Management Quest.
James Boother Blog: INTRODUCTION TO POWERSHELL.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows.
Basic.  Powershell scripts are flat text files that end with “.ps1” (e.g. myscript.ps1)  Similar to other scripting languages, whatever you can do on.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
System Center 2012 R2 Windows Azure Pack Service Management Automation 101.
Adding a Module The Import-Module cmdlet  Can be used to load any external module into PowerShell.  Uses the following syntax to add the ActiveDirectory.
Microsoft ® Official Course Module 4 Automating Active Directory Domain Services Administration.
A First Program Using C#
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Introduction To PHP 20 * Introducing the basics of programming * Discovering variables, loops, arrays and conditions * Integrating HTML and PHP Stations.
MS WINDOWS POWER SHELL CSE 535 Operating Systems.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Microsoft ® Official Course Module XA Using Windows PowerShell ®
PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.
Python: An Introduction
Introduction to Matlab & Data Analysis
Appendix A Starting Out with Windows PowerShell™ 2.0.
Section 1: Introducing Group Policy What Is Group Policy? Group Policy Scenarios New Group Policy Features Introduced with Windows Server 2008 and Windows.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Best Practices for Script Design A PowerShell.org TechSession.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based.
Linux+ Guide to Linux Certification, Third Edition
Good Morning and Thank You!.  Have some Fun!  Learn at least one thing new!  Make myself available to you So please …  Ask questions and enjoy!
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introduction to Unix – CS 21
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
What’s New in SharePoint 2010 SharePoint 2010 Development Primer New Developer Tools for SharePoint 2010 SharePoint 2010 Integration with PowerShell.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Corey Hynes HynesITe, Inc Session Code: SRV317 Objectives Let you walk out of here, being able to run a script against an OU of computers, to make some.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
 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.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Module 14: Advanced Topics and Troubleshooting. Microsoft ® Windows ® Small Business Server (SBS) 2008 Management Console (Advanced Mode) Managing Windows.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introduction to SQL Server Automation with Powershell by Chris Sommer.
Ravikanth C.
Start-SPPowerShell – Introduction to PowerShell for SharePoint Admins and Developers Paul BAker.
MIKADO – Generation of ISO – SeaDataNet metadata files
ASP.NET Programming with C# and SQL Server First Edition
Data Virtualization Tutorial: Introduction to SQL Script
PYTHON: AN INTRODUCTION
SharePoint Saturday Omaha April 2016
CIS16 Application Development Programming with Visual Basic
Cmdlets “Command-lets”
Presentation transcript:

© 2010 Quest Software, Inc. ALL RIGHTS RESERVED Techstravaganza 2010 PowerShell 101 Dmitry Kagansky Solutions Architect - Quest Software (Public Sector)

2 Introduction & Administrative Items Agenda –Dmitry Kagansky PowerShell 101 –Aaron PowerShell and Server Management –Barry Gerdsen PowerShell and Active Directory PowerGUI PowerShell Scripting & Debugging Expectations

3 What is PowerShell? Blah blah blah – you’ve heard it all before However, these are some things to keep in mind It is Object Oriented –What? It is extensible –“Snap-ins” is the word of the day It is baked into Windows It is mandatory for some products –Exchange It’s now up to version 2.0!

4 Unified and Standardized Exchange Get-Mailbox –Database 'VIP' | Set-Mailbox –MaxReceiveSize 'unlimited' Active Directory Get-QADUser –City 'Aliso Viejo' | Set-QADUser -PhoneNumber ' ' VMware Get-VM -Name web* | Set-VM –MemoryMB 1024

5 Where to begin? “Blue is the new black” The console

6 So how did I start? I stumbled around and tried things First new word –cmdlets The only cmdlet I can reliably remember –Get-Help save it for the lab cmdlet format –Verb-noun Aliases

7 cmdlets Verb-Noun –No ‘real’ standard to separate out separate vendor cmdlets (Quest uses Verb-QNoun but another snap-in could break this) I lied; I can also remember: –Get-Command

8 How It Works filtering, etc. Get-Something Do-Something Collection of objects

9 PowerShell for Reporting Get-* to retrieve information on most objects Sorting, Filtering, Grouping Tables, Lists Output to XML, CSV, HTML On the fly calculations

10 Perfect for Bulk Operations Bulk changes Provisioning from csv Snapshots Learn to love the pipe –| –(and its red-headed step-children, the redirectors)

11 Natively Supports Modern Technology HTML Reporting CSV XML Web Services Get-QADUser | ConvertTo-Html –Property Name, Title

12 Natively Supports Modern Technology HTML Reporting CSV XML Web Services Get-Mailbox | Export-CSV c:\out.csv

13 Natively Supports Modern Technology HTML Reporting CSV XML Web Services $data = [XML] Get-Content c:\data.xml $data.chapter $data = [XML] Get-Content c:\data.xml $data.chapter

14 Natively Supports Modern Technology HTML Reporting CSV XML Web Services $zip = New-WebServiceProxy –uri `

15 Variables, Arrays, and Hash Tables Variables - allows us to store single bits of information –$firstName Arrays - allows us to store information in a sequentially numbered index –$strComputers[x] Hash Table - allows us to store in key/value pairs (like Arrays but referenceable by name) –$strEmployeeID[“Dmitry K”]

16 Special Variables $_: Contains the current pipeline object, used in script blocks, filters, and the where statement $Args: Contains an array of the parameters passed to a function $Error: Contains objects for which an error occurred while being processed in a cmdlet $Home: Specifies the user’s home directory $PsHome: The directory where the Windows PowerShell is installed I give up – just run: _ Get-Help about_automatic_variables

17 Conditional Logic Comparing data if/else/elseif OperatorDescription -eqEqual to -ltLess than -gtGreater than -geGreater than or Eqaul to -leLess than or equal to -neNot equal to If (this –eq boring) {surf-web} else {pay-attention}

18 Looping Looping is the key to batch work Common loop constructs –do while: - Script block executes as long as condition value = True –while: Similar to “do while” –do until: Script block executes until the condition value = True –for: Script block executes a specified number of times –foreach: Executes script block for each item in a collection or array

19 Output & Feedback Lots of ways to do it –Write-Host –Out-File –Redirection –Lots of ways.... Get-Command *export* Get-Command *out* Get-Command *write* Get-Command *export* Get-Command *out* Get-Command *write*

20 Redirection Cheat Sheet OperatorDescription > Redirects output to specified file. If the file already exists, current contents are overwritten. >> Redirects output to specified file. If the file already exists, the new output is appended to the current content. 2> Redirects error output to specified file. If the file already exists, current contents are overwritten. 2>> Redirects error output to specified file. If the file already exists, the new output is appended to the current content. 2>&1 Redirects error output to the standard output pipe instead of to the error output pipe.

21 Demonstration

22 Dissecting some code From that-gpo-using-a-quest-product-of-course/ Follow it with me

23 import-csv deletelist.csv | % {& Delete-QGPO.ps1 $_.GPOName $_.GPMServer} import-csv deletelist.csv | % {& Delete-QGPO.ps1 $_.GPOName $_.GPMServer} Dissecting some code

24 ##################################################### # In an ideal world, this would be a cmdlet called: # Delete-QGPO GPOName [-GPMServer] ##################################################### # define the GPO name, which is what people # will probably know it as – this # can be an argument to a script later $gpoName = $args[0]; # Which GPM Server to export from $GPMHostname = $args[1]; $GPMPort = 40200; ##################################################### # In an ideal world, this would be a cmdlet called: # Delete-QGPO GPOName [-GPMServer] ##################################################### # define the GPO name, which is what people # will probably know it as – this # can be an argument to a script later $gpoName = $args[0]; # Which GPM Server to export from $GPMHostname = $args[1]; $GPMPort = 40200; ##################################################### Dissecting some code

25 & 'C:\Program Files\Quest Software\Quest Group Policy Manager\QGPMInit.ps1' -computerName $GPMHostname Dissecting some code

26 $foundGPO = $false ; # loop through all the objects in the data set and find the policy we want foreach($currentGPO in $VCManager.GetControlledObjects("GPO") | Where-Object {$_.Name -eq $gpoName}) { $foundGPO = $true; # check out the GPO so we can edit it # you can discard the contents # returned since we want a previous version $VCManager.Delete($currentGPO.VCId, "Deleting GPO - bye bye"); Write-Output “deleting GPO $gpoName"; } $foundGPO = $false ; # loop through all the objects in the data set and find the policy we want foreach($currentGPO in $VCManager.GetControlledObjects("GPO") | Where-Object {$_.Name -eq $gpoName}) { $foundGPO = $true; # check out the GPO so we can edit it # you can discard the contents # returned since we want a previous version $VCManager.Delete($currentGPO.VCId, "Deleting GPO - bye bye"); Write-Output “deleting GPO $gpoName"; } Dissecting some code

27 if ($foundGPO -eq $false) { Write-Output "GPO $gpoName not found”; } if ($foundGPO -eq $false) { Write-Output "GPO $gpoName not found”; } Dissecting some code

28 ##################################################### # In an ideal world, this would be a cmdlet called: # Delete-QGPO GPOName [-GPMServer] [-GPMPort] ##################################################### # define the GPO name, which is what people will probably know it as – this # can be an argument to a script later $gpoName = $args[0]; # Which GPM Server to export from $GPMHostname = $args[1]; $GPMPort = 40200; ##################################################### & 'C:\Program Files\Quest Software\Quest Group Policy Manager\QGPMInit.ps1' -computerName $GPMHostname $foundGPO = $false ; # loop through all the objects in the data set and find the policy we want foreach($currentGPO in $VCManager.GetControlledObjects("GPO") | Where-Object {$_.Name -eq $gpoName}) { $foundGPO = $true; # check out the GPO so we can edit it # you can discard the contents returned since we want a previous version $VCManager.Delete($currentGPO.VCId, "Deleting GPO - bye bye"); Write-Output “deleting GPO $gpoName"; } if ($foundGPO -eq $false) { Write-Output "GPO $gpoName not found”; } ##################################################### # In an ideal world, this would be a cmdlet called: # Delete-QGPO GPOName [-GPMServer] [-GPMPort] ##################################################### # define the GPO name, which is what people will probably know it as – this # can be an argument to a script later $gpoName = $args[0]; # Which GPM Server to export from $GPMHostname = $args[1]; $GPMPort = 40200; ##################################################### & 'C:\Program Files\Quest Software\Quest Group Policy Manager\QGPMInit.ps1' -computerName $GPMHostname $foundGPO = $false ; # loop through all the objects in the data set and find the policy we want foreach($currentGPO in $VCManager.GetControlledObjects("GPO") | Where-Object {$_.Name -eq $gpoName}) { $foundGPO = $true; # check out the GPO so we can edit it # you can discard the contents returned since we want a previous version $VCManager.Delete($currentGPO.VCId, "Deleting GPO - bye bye"); Write-Output “deleting GPO $gpoName"; } if ($foundGPO -eq $false) { Write-Output "GPO $gpoName not found”; } Dissecting some code: The whole script

29 $gpoName = $args[0]; $GPMHostname = $args[1]; $GPMPort = 40200; & 'C:\Program Files\Quest Software\Quest Group Policy Manager\QGPMInit.ps1' -computerName $GPMHostname $foundGPO = $false ; foreach($currentGPO in $VCManager.GetControlledObjects("GPO") | Where-Object {$_.Name -eq $gpoName}) { $foundGPO = $true; $VCManager.Delete($currentGPO.VCId, "Deleting GPO - bye bye"); Write-Output “deleting GPO $gpoName"; } if ($foundGPO -eq $false) { Write-Output "GPO $gpoName not found”; } $gpoName = $args[0]; $GPMHostname = $args[1]; $GPMPort = 40200; & 'C:\Program Files\Quest Software\Quest Group Policy Manager\QGPMInit.ps1' -computerName $GPMHostname $foundGPO = $false ; foreach($currentGPO in $VCManager.GetControlledObjects("GPO") | Where-Object {$_.Name -eq $gpoName}) { $foundGPO = $true; $VCManager.Delete($currentGPO.VCId, "Deleting GPO - bye bye"); Write-Output “deleting GPO $gpoName"; } if ($foundGPO -eq $false) { Write-Output "GPO $gpoName not found”; } Dissecting some code: The whole script

30 Remember this? - Unified and Standardized Exchange Get-Mailbox –Database 'VIP' | Set-Mailbox –MaxReceiveSize 'unlimited' Active Directory Get-QADUser –City 'Aliso Viejo' | Set-QADUser -PhoneNumber ' ' VMware Get-VM -Name web* | Set-VM –MemoryMB 1024

31 PowerShell 2.0 – What’s new See for details An update of not just PoSh but the entire Windows Management Framework Remoting –run commands on one or more remote computers from a single computer Integrated Scripting Environment –run interactive commands and edit and debug scripts in a graphical environment. Modules –partition and organize Windows PowerShell code in self-contained, reusable units. Advanced functions –Advanced functions are functions that have the same capabilities and behavior as cmdlets but not written in compiled C#. Background jobs –allows for running a command or expression asynchronously and "in the background" without interacting with the console. Eventing –adds support for listening, forwarding, and acting on management and system events. Script internationalization –enables scripts to display messages that is specified by the UI culture setting on the user's computer. Script debugging –New features were added to Windows PowerShell that let you do more during debugging. New cmdlets –introduces over 100 built-in cmdlets.

32 Thank You

33 Additional Info Special user group pricing on PowerGUI Pro ($99) –

34 Resources MSDN PowerShell Blog – Good Starting Tutorial – PowerGUI Community – Free Tools from Quest –Look for PowerGUI and the AD cmdlets at: