Cmdlets “Command-lets”

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

MIRC Matthew Forest. Introduction mIRC itself is a program designed for text based messaging via the IRC (internet relay chat) protocol. (Link:
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Working with Files Chapter 5. Display a Calendar Display a calendar for a specific month – cal Display a calendar for a specific year – cal 2000.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
More Command Line Options Pipes, Redirection, Standard files Copyright © 2015 Curt Hill.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © Curt Hill.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Windows Builder An Eclipse Plugin for Creating Windows Graphical User Interfaces Copyright © 2014 Curt Hill.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 7 Files.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
File and Folder CLI Commands 12/24/ Agenda Overview of OS functions and the SHELL Internal v External Commands Command History Making & Modifying.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
 It is Microsoft's new task-based command- line shell and scripting language designed especially for system administration.  It helps Information Technology.
Recipes How to craft items from others Copyright © 2015 Curt Hill.
Copyright © – Curt Hill Building Windows Applications in wxDev-C++
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Copyright © Curt Hill Common Dialogs Easily Obtaining File Names in DevC++ Windows Programs.
Batch Files Flow of Control to Strengthen Copyright © by Curt Hill.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Batch Files More flow of control Copyright © by Curt Hill.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Mostly MS Dos with some UNIX/LINUX
PowerShell SUNISH SURENDRAN KANNEMBATH
User-Written Functions
PowerShell Introduction Copyright © 2016 – Curt Hill.
An Eclipse Plugin for Creating Windows Graphical User Interfaces
BIT116: Scripting Loops.
Data Virtualization Tutorial… CORS and CIS
Play Framework: Introduction
Some Linux Commands.
Documentation Generators
Console and GUI Programs
Arrays and files BIS1523 – Lecture 15.
An Automated Testing Framework
Getting Started with the Data ONTAP PowerShell Toolkit
Files and Streams Lect3 CT1411.
Multi-host Internet Access Portal (MIAP) Enhancement Guide
Introduction to javadoc
Predefined Dialog Boxes
Copyright © – Curt Hill Bash Scripting Fundamentals Copyright © – Curt Hill.
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Shell Commands Using BASH Copyright © 2017 Curt Hill.
Compilers, Make and SubVersion
PowerShell Best Practices for SQL DBA’s
UNIX/LINUX Commands Using BASH Copyright © 2017 – Curt Hill.
Introduction to javadoc
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
CSE 303 Concepts and Tools for Software Development
Functions, Parameters and Scope
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Module 6 Working with Files and Directories
Java Looking at our first console application in Eclipse
Running a Java Program using Blue Jay.
Microsoft Office Illustrated Fundamentals
An Eclipse Plugin for Creating Windows Graphical User Interfaces
Topics Introduction to File Input and Output
Presentation transcript:

Cmdlets “Command-lets” PowerShell Cmdlets “Command-lets” Copyright © 2016 – Curt Hill

Introduction Previously, we considered: Similarity of PowerShell to the DOS Command Box Scripting basics Scripting flow of control Now we examine in more detail the notion of a cmdlet These are lightweight commands that perform an action and usually return a .NET object Copyright © 2016 – Curt Hill

Differences From Commands Cmdlets are instances of .NET Framework classes Not stand-alone executables Cmdlets usually do not parse, display errors, or format output This is handled by PowerShell Cmdlets process input objects rather than streams of text Cmdlets are record-oriented because they process a single object at a time Object may contain several things Copyright © 2016 – Curt Hill

Form Cmdlets use a verb-noun pair to identify a cmdlet These are followed by options or items to act upon An alias may exist that makes the cmdlet resemble a previous DOS command Lets consider the copy-item cmdlet Copyright © 2016 – Curt Hill

Copy-Item Takes two strings as parameters The copy from string The copy to string Both should refer to one or more files Wildcards may be used The aliases include Cp Copy Cpi Options include -recurse Copyright © 2016 – Curt Hill

Aliases These are provided to make it more convenient for users Especially from other systems The COPY-ITEM cmdlet has as aliases the following: CP – for UNIX/LINUX users CPI – just an appreviation COPY – for DOS users Copyright © 2016 – Curt Hill

Item In the previous cmdlet there were two pieces What is an Item? The verb was Copy The noun was Item What is an Item? It could be: Variable File Among others Copyright © 2016 – Curt Hill

Item Verbs Get – gives entries for files Move – Copy + delete original Similar to get-childitem, which also shows subdirectories If you give it a variable it interprets as file Move – Copy + delete original New – creates a new file Use –type directory for a new directory Remove – deletes Use –recurse to remove subdirectories Rename – Guess what this does Copyright © 2016 – Curt Hill

Assignment Not only will a cmdlet do some useful action It may also be used to produce values for variable It can be saved in variable using: $files = get-childitem Wildcards could be used after get-childitem Copyright © 2016 – Curt Hill

Piping As in DOS the vertical bar (|) is the pipe directive This transfers the output of one program into the input of another This is frequently done with cmdlets as well We will see examples later Copyright © 2016 – Curt Hill

Perhaps Useful Cmdlets Add-content file data Append the data to the end of a file Clear-content file Empties a file, but does not erase Compare-object Shows what is in one or other Does not show both Two should be same type Copyright © 2016 – Curt Hill

More Cmdlets Get-content file Set-content file Test-path file Gets the file content Set-content file Creates file if needed Test-path file Returns true if file exists Wildcards may be used Write-host Displays strings to console Copyright © 2016 – Curt Hill

Content The {Add|Clear|Get|Set}-Content only works well for text files Any specialized format will likely be damaged by Add, Clear or Set and return garbage for Get Copyright © 2016 – Curt Hill

Convert to HTML Yes this is a cmdlet Any command that produces a display may be piped into this The result may be manipulated further or set into a file Here are two screen shots Copyright © 2016 – Curt Hill

Creating HTML Copyright © 2016 – Curt Hill

Viewing Copyright © 2016 – Curt Hill

Help The cmdlet get-command lists all the cmdlets available on this system There are typically hundreds Use Help and the cmdlet name to find out more about each If you need more help still use the –online parameter This will take you to a web site Copyright © 2016 – Curt Hill

More Help You can find the files in a directory Use get-item or get-childitem What can be done with this information? Pipe it into get-member This will show the properties and methods Copyright © 2016 – Curt Hill

Properties and Methods Any variable may contain an object of any number of types It depends how the variable was set Get-member shows the available properties and methods A property or method is used by following the item with a dot and then giving the property or method name A method must be followed by parenthesis Usually empty Copyright © 2016 – Curt Hill

Example In this example the following will be done The get-item cmdlet will find the information on .PPT files in a directory It will assign to a variable The properties and methods of that data will be shown Two properties and one method will be exercised This will use 5 screen shots Copyright © 2016 – Curt Hill

Assigning Copyright © 2016 – Curt Hill

Finding Members Copyright © 2016 – Curt Hill

Finding Again Copyright © 2016 – Curt Hill

Properties Copyright © 2016 – Curt Hill

Methods Copyright © 2016 – Curt Hill

Finally As you can see there is lots more to know What we need now is a demonstration Then an exercise We will need to look at parameters and scope Then an assignment Copyright © 2016 – Curt Hill