Administration and Automation with Windows PowerShell

0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 42min

0 / 7 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete

You need to sign up to get access!

Sign up to get full access to this course.

Sign up to access this lesson

Click here to sign up and get access to this lesson!

Saving Progress...

The Pipeline Part 2

As you already know pipeline parameter binding is the method of stringing together the right cmdlets to perform a task.

Byvalue or Byproperty is the glue that PowerShell uses to allow the output of one command to pass to the input of the second command

In the last lecture we demonstrated how to get commands through the pipeline Byvalue. 

In this lecture, we’ll demonstrate how PowerShell uses parameter binding byproperty.

We’ll introduce two new commands:

  • import-csv and the new-alias command.
  • The Import-Csv cmdlet creates table-like custom objects from the items in 

CSV files. Each column in the CSV file becomes a property of the custom 

object and the items in rows become the property values

  • The New-Alias cmdlet creates a new alias in the current PowerShell session. 

let’s Open windows explorer. From your c: drive create a folder named test. Close explorer

Now we’ll use notepad to create a csv (Comma separated value) file and copy that to our test folder.

  • From the search bar type notepad
  • Now type the following:

Name, Value

L, eventlog

List, get-childitem

P, ping

W, winver

Now from file, click save-as. Click the C: drive and click the test folder

For a file name type aliases.csv 

Change save as type, press the down arrow and change .txt to All Files. 

Now click save., then click close.

Now, the parameter binding process that PowerShell uses to determine what commands pass through the pipeline is basically the same for byproperty and for byvalue, with a few differences. 

For command #1 you still use get-member and for command #2 you still use get-help. The difference is that now you are looking for things that are byproperty instead of byvalue.

  • Command 1 which in this case is import-csv. We’ll use get-member to get the property and methods of the object import-csv.
  • Command 2 will be New-Alias. We’ll us get-help –full to get the parameters that take byproperty.
  • Now we’ll open two PowerShell windows.
  • Type import-csv -path c:\test\aliases.csv | gm now press return

If you recall from our object’s lecture. Objects can have properties or methods. But what we’re interested in is properties and in this case Powershell displays them as noteProperty 

  • (NoteProperties are just generic properties that are created by Powershell)
  • Notice that Name and Value match the column headings from our csv file.

Now we need to use get-help to determine if Command 2 or in this case New-alias has a parameter that will bind with command 1 ByProperty

  • Type get-help new-alias -full press return
  • Scroll up until you see a parameter that says ByPropertyName
  • So, we see that the -Value and -Name parameters both accept pipeline input BypropertyName

These two commands should work because:

Command one which is import-csv passed two properties called name and value across the pipeline to the second command which is new-alias

From the second command new-alias Get-help told us that the parameters -name and -value can take pipeline input by propertyname

So, these command should work. We can test that by typing (press return)

Sign up to access the rest of this lesson

You must either log in or sign up to access this lesson.

Saving Progress...

0 0 votes
Lesson Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments