Windows PowerShell. What is Windows PowerShell? A command-line interface (CLI) A new way of developing Windows and other products to be more manageable.

Slides:



Advertisements
Similar presentations
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Advertisements

Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Microsoft PowerShell Tom Roeder CS fa. Motivation.NET as a platform shell web server database access Native access to resources eaiser to manage.
Jason Himmelstein, MVP Senior Technical Director,
James Boother Blog: INTRODUCTION TO 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.
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.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
INTRODUCTION TO POWERSHELL Neil Iversen. Points of Interest  Introduction  Getting Around  Basic Syntax  Making yourself at ~  Not-So-Basic Syntax.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Managing Active Directory with PowerShell JOSEPH MOODY.
Basic.  PS is a command line interpreter/scripting environment  Designed for.Net  Similar to C#  Easy to instantiate.Net classes  Standardized syntax.
POWERSHELL Dr. Sarah Gothard CEG 233 Spring 2010.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
© 2007 Asynchrony Solutions, Inc. 1 10/29/07 Introduction to PowerShell Brian Button VP Engineering Asynchrony Solutions, Inc
MS WINDOWS POWER SHELL CSE 535 Operating Systems.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Windows PowerShell Deep Dive 1 Morgan Simonsen Ementor.
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.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Appendix A Starting Out with Windows PowerShell™ 2.0.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based.
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.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
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!
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CN1266 Network Scripting V1.2 Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Controlling Execution Dong Shao, Nanjing Unviersity.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
PowerShell For SharePoint Developers Neil Iversen Inetium
Shell Programming Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn the.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Windows PowerShell Introduction 1 Morgan Simonsen Ementor.
 An alias is an alternative name assigned to a Cmdlet.  Aliases allow users to quickly interact with the shell.  The Cmdlet get-alias is.
Files Tutor: You will need ….
CIS 1402: Intro to CIS Tom Gustafson. Facts About PowerShell PowerShell is Microsoft’s command-line interface that provides scripting and management capability.
POWERSHELL BASICS. BACKGROUND  Powershell is a task automation and scripting language based off the.NET framework  It provides the user full access.
 It is Microsoft's new task-based command- line shell and scripting language designed especially for system administration.  It helps Information Technology.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
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.
Linux Administration Working with the BASH Shell.
Ravikanth C.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
CSC 352– Unix Programming, Fall 2012
Deploying and Configuring SSIS Packages
Introduction to PowerShell
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
PowerShell Best Practices for SQL DBA’s
Cmdlets “Command-lets”
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
CSC 352– Unix Programming, Fall, 2011
Introduction to Bash Programming, part 3
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Windows PowerShell

What is Windows PowerShell? A command-line interface (CLI) A new way of developing Windows and other products to be more manageable An interactive shell * as well as a simplified scripting language. PowerShell connects to existing administrative functionality: WMI.NET Framework COM ADSI Allows you to partially administer non-PowerShell technologies today Over time, more and more products will be “fully exposed” to PowerShell.

Why CLI? A GUI is great for doing something once. Performing anything multiple times in a GUI becomes boring and error-prone. A CLI is inherently better when it comes to automating repetitive tasks.

The PowerShell Advantage Bring all functionality together in one spot. Expose the functionality to be used by a GUI or a script. Create that functionality in a consistent fashion (e.g. learn one way to do everything)

Using PowerShell

Introducing Cmdlets (Command-lets) Cd, Ls, Copy, and Cp are all cmdlets. Technically, these are aliases, or nicknames, to the actual cmdlets. Cmdlets are written in a.NET Framework language. Cmdlets are bundled into DLL files called snap-ins or PSSnapIns. NOTE: cmdlets are not case sensitive. So Help Get-ChildItem is the same as help get-childitem.

Aliases Aliases are just short names for cmdlets. They’re easier to type. They provide consistency with old-style command names. Many aliases come built in. You can create your own!

That’s why “dir /s” does not work Dir is an alias for Get-ChildItem. The alias only covers the cmdlet name—it doesn’t change the parameters the cmdlet uses. Get-ChildItem uses a different parameter to recurse subdirectories. Dir –recurse or Dir -r will do the trick. NOTE: To break any command that is taking forever, press CTRL + C.

Getting help Well, expect you can’t memorize all of the commands, how it works, or its syntax. Here’s when help comes in handy. Help is an alias for the cmdlet Get-Help. Usage: Get-Help If you hate reading help in the console, you can always search the web!

Cmdlet Consistency Cmdlet names might seem long *, but there’s a reason. Consistent verb-singular noun naming means you can guess what a cmdlet name would be based on the functionality you want. This makes learning to use the shell easier. Examples: Get-Command Get-Process Get-Service New-Alias New-Service

Parameter Rules Parameters are documented in Help. Parameters names are preceded by a dash. A space separates the parameter name and its value. Some commands have positional parameters don’t need the name at all—just type the values in the correct order. Example: New-Alias [-name] [-value] New-Alias -name "d" -value "Get-ChildItem" New-Alias "d" "Get-ChildItem"

PowerShell Pipeline Or the passage of the process of the commands

Through the process Similar to database queries pipelines. So far the cmdlets you’ve run have seemed to produce text lists as their output. But behind the scenes, they’re actually working with objects *. When you run a cmdlet, it generally produces objects as its output. These objects are actual functioning pieces of Windows. Get-Service doesn’t product a list of services, it grabs all the actual services which are installed on the computer.

Service You can check its.NET Framework class on This object has the following properties: Name IsStarted DisplayName ServiceType Status And so on… The text list you see consists some of these properties’ values.

The Pipeline All cmdlets run in a pipeline. The objects a cmdlet outputs go into the pipeline… …and the next cmdlet in the pipeline picks up whatever objects are in the pipeline. At the end of the pipeline is a special cmdlet called Out-Default (no need to specify). Out-Default takes whatever object are in the pipeline, and uses their properties (at least one) to construct a text output.

A simple pipeline example

Why Objects? You don’t need to use text as an intermediary. You can work directly with the built-in functionality of whatever object you are manipulating. No parsing required! Easier output formatting. TIP: Don’t know properties of an object? Try using Get-Member command at the end of the pipeline. Example: Get-Service Get- Member returns the methods and properties of a service object.

Another example of the pipeline Get-EventLog "Windows PowerShell" | Select -first 10 | Sort InstanceID | ConvertTo-HTML | Out-file "C:\Users\EarlPeterJ\Desktop\test.html" The cmdlet separator is a vertical bar line |. You can use as many commands as you want.

Scripts Script files contains commands you execute in PowerShell. Why? To reduce redundant typing of a long or complex command. Allows you to share it with your co-workers, friends, and any other people. File extension is.PS1. NOTE: Be careful when executing PS1 scripts since they may contain functions that access critical Windows components. Further research: PowerShell Security TIP: Multiple lines to type in PowerShell? Press Shift + Enter to enter new line instead of executing it.

Operators & Filtering

Comparisons The purpose of a comparison is to generate True or False result. PowerShell provides the $True and $False variables to represent these Boolean values. All comparisons result in either $True or $False. Comparison Operators: -eq, -ne, -gt, -lt, -ge, and le

Logical Operators When you need to compare more than one expressions, you can use these logical operators: -and, -or, and -not I think you already know how to use them, so I don’t have to explain them.

Comparison Examples $_ represents the current object being handled. So we can use it in the following statements: $_.UserName -eq “EarlPeterJ” $_.EntryType –nq “Information” We can use this expressions on Where cmdlets (much like your DB queries) after your command. Example: Get-EventLog "Windows PowerShell" | where {$_.EntryType -eq "Warning"} NOTE: Make sure you place curly braces between your queries and parenthesis between each expression. Multiple Expressions Example: Get-EventLog "Windows PowerShell" | where {($_.EntryType -eq “Information“) -and ($_.InstanceID -gt 400)}

Select cmdlet As you noticed, there is a default format on how PowerShell outputs objects. Select-Object allows you to customize what is passed down the pipeline. Usage: Select separate by comma Or: -first / -last

Sort cmdlet and Group cmdlet Sort-Object allows you to sort the list of output based on one or more properties. Usage: sort separate by comma [-descending optional ] Example: get-process | sort name Group-Object groups objects that contain the same value for specified properties. NOTE: Sorting before grouping has no effect on the grouping cmdlet. Example: get-service | group status

Working with each object ForEach-Object (or foreach) allows you to loop through each object. Much like where cmdlet, use $_ as the variable for the current object. Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan}

Variable declaration You can declare variables preceded by dollar sign $. Follow same variable naming convention as in any other programming languages Example: $url = ' $wc = New-Object System.Net.WebClient $wc.DownloadString($url)

get-content "C:\Users\EarlPeterJ\Desktop\test.txt" | foreach { (new-object System.Net.WebClient).DownloadString($_) }