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.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Getting Started with VMware PowerCLI Jake Robinson, Systems Engineer Bluelock 1.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Rick Toner MCSD, MCPD, MCITP Blog:
Microsoft PowerShell Tom Roeder CS fa. Motivation.NET as a platform shell web server database access Native access to resources eaiser to manage.
Basic.  Defining functions  Internals and parameters  Returning values  Scoping values  Using functions as filters.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
Windows PowerShell Codename: “Monad”.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Practical Extraction & Report Language Picture taken from
Tutorial 10 Programming with JavaScript
Microsoft ® shell scripting environment Gives administrators more power and command in the shell environment – Hence…PowerShell? Active Directory Module.
POWERSHELL Dr. Sarah Gothard CEG 233 Spring 2010.
Microsoft ® Official Course Module 4 Automating Active Directory Domain Services Administration.
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.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Windows PowerShell Deep Dive 1 Morgan Simonsen Ementor.
PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Nael Alian Introduction to PHP
Writing C-shell scripts #!/bin/csh # Author: Ken Berman # Date: # Purpose: display command and parameters echo $0 echo $argv[*]
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Website Development with PHP and MySQL Saving Data.
CN1266 Network Scripting V1.2 Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Introduction to Unix – CS 21
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
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)
 An alias is an alternative name assigned to a Cmdlet.  Aliases allow users to quickly interact with the shell.  The Cmdlet get-alias is.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
 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.
Week 3 Objectives Manage User Accounts Manage Group Accounts Manage Computer Accounts Delegation Use Commandline Tools and Windows PowerShell for AD DS.
Microsoft ® Official Course Module 4 Automating Active Directory Domain Services Administration.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Ravikanth C.
Building Powerful Workflow Automation with Cherwell and PowerShell
Y.-H. Chen International College Ming-Chuan University Fall, 2004
>> Introduction to JavaScript
Connect:Direct for UNIX v4.2.x Silent Installation
Introduction to PowerShell
PHP Introduction.
Expressions and Control Flow in JavaScript
Agenda Control Flow Statements Purpose test statement
Introduction to PowerShell
When I want to execute the subroutine I just give the command Write()
WEB PROGRAMMING JavaScript.
PHP.
Tutorial 10 Programming with JavaScript
Introduction to javadoc
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

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 a command line, you can place in the script.

 Unlike cmd.exe, the current folder is not automatically searched – it must be in your path or explicitly noted on the command line (eg.\myscript )  If you double click on a Powershell script from Windows Explorer it will open up the script in notepad.exe by default.  You must explicitly set the execution policy…

 Restricted – Only interactive commands will run at the console.  AllSigned – Scripts must have a certificate issued by a trusted party.  RemoteSigned – Scripts downloaded require a 3 rd party certificate. Local scripts will run without a certificate.  Unrestricted - All scripts run without restriction.

 To set the privilege you must have administrator privileges.

 In your working folder enter the following command:

param([int]$height, [decimal]$shoesize, [int]$weight) "Height: " + $height "Shoe: " + $shoesize "Weight: " + $weight if (($height * $shoesize) -gt $weight) { Write-Host "You are either tall or you have big feet." } else { #try to be politically correct here Write-Host "You have the perfect weight." }

param([int]$height, [decimal]$shoesize, [int]$weight) "Height: " + $height "Shoe: " + $shoesize "Weight: " + $weight if (($height * $shoesize) -gt $weight) { Write-Host "You are either tall or you have big feet." } else { #try to be politically correct here Write-Host "You have the perfect weight." } Named parameter With strong typing Concatenation and Conversion Comment

#PSCount-Lines #Demonstration code begin { $lineCount = 0 } process { $lineCount++ } end { Write-Host "There are " $lineCount " lines." }

begin { $lineCount = 0 if ($args[0] -eq "-Double"){ $multiplier = 2 } else { $multiplier = 1 } } process { $lineCount++ } end { Write-Host "There are " ` ($multiplier * $lineCount) " lines." }

 If…. elseif… else…  Switch…… default  ForEach ( Foreach-Object )  For  While  Do….. While  Do…..Until  Break & Continue

OperatorDescription -eqEquals -neNot equal -gtGreater than -geGreater than or equal -ltLess than -leLess than or equal -containsThe collection contains the value -notcontainsThe collection does not contain a value

OperatorDescription -notNOT ! -andAND -orOR

$processes = get-process if ($processes.Length -gt 50) { write-host "Processes are high: " + $processes.Length } $pnames = &{foreach ( $i in $processes ) {$i.Name}} if ($pnames -contains "notepad") { Write-host "Notepad is running." }

-like To be like as -notlike To not be like as -match Match -notmatch Not match -contains Include -notcontains Not include

Switch [-regex|-wildcard|-exact][-casesensitive] -file ( ) { { code 1 } { code 2 } { code 3 } … Default { code n } }

CommandsFunctions Format -Custom -List -Table -Wide Convert objects into formatting records Out -File -Host -Printer -String Convert formatting records into output-specific directives. Export/Import -CliXML -CSV Converts objects into and out of file formats ConvertTo -HTML Converts object into other objects

function listLastEvent { param ([int] $lastLimit) Get-EventLog -Newest $lastLimit Security Get-EventLog -Newest $lastLimit System Get-EventLog -Newest $lastLimit Application } listLastEvent 3 | ` Select Username, Source, TimeGenerated, Message | ` ConvertTo-Html > /temp/myreport.html Invoke-Item /temp/myreport.html

 Functions can return values  $LastExitCode will capture the exit value of the last executable from the command line  $? – Similar to Unix but it holds either $true or $false to indicate success of the last call  $error – A collection of all the error messages so far ($error[0] is the most recent)

param ($filename = "/temp/nemo") dir $filename 2>$null if ($?) { Write-Host "That worked."} else {(Write-Host "Could not find: " $filename) }