Posts

Showing posts with the label Pipeline

DAY- 9 : Advance Pipeline-2

Image
Custom Properties It's pretty easy to make property and parameter names line up when you're creating the input from scratch. Things get tougher when you're forced to deal with the objects that are created for you or data that's being produced by someone else. For example, we're going to introduce a new command that you might not have access to New-ADUser. It is a part of Active Directory module. New-ADUser has a number of parameters, each designed to accept information about a new Active Directory user. Here are some examples: 1. Name( this is mandatory ) 2. Samaccountname 3. Department 4. City 5. Title For this example, we'll again assume you're getting a csv file, but it's coming from your company's HR department. You've given them your desired file format dozen of time but they persist in giving you something that's close but not quite right as shown below. As you can see in above fig. that...

DAY 8 - Advance Pipeline

Image
At this, point you've learned to pretty effective with PowerShell's Pipeline. Running Pipeline commands is powerful, accomplishing in one line what used to take several lines of the script. But if I said you can even do better than this, in this blog we'll dig deep into the pipeline and discover its powerful capabilities.  How PowerShell Passes Data Down to Pipeline Whenever you string two commands in a pipeline, PowerShell has to figure out how to get the output of the first command to the input of the second command. Let say the first command as command A and the second command as command B. A will produce something and B, which needs to accept A's output as input and then do its own thing. Command A | Command B For example, suppose you have a text file that contains one computer name on each line. You might want to use those names as the input to some command, telling that command which computers you want to run against. Get-cont...

DAY-4: PowerShell Pipeline and Exporting Data

Image
Pipeline - Connecting commands   PowerShell connects commands to each other using something called a Pipeline. The pipeline provides a way for one command to pass, or pipe, its output to another command, allowing that second command to have something to work with. The concept of joining commands is not limited to PowerShell, but PowerShell takes the same piping to a greater extend for better effect.  Exporting Output to Files 1. Get-Process 2. Get-service When we run above commands, a table with several columns of information appears on the screen.  It's great to have information on the screen, but that isn't all you might want to do with the information. For example, if you want to export the information into a CSV file that could be read into an application like Microsoft excel.  Exporting to CSV Exporting to a file is where the pipeline and a second command come in handy. Get-Process | Export-csv C:\procs...