Posts

Showing posts with the label Learn PowerShell

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-7: POWERSHELL OBJECT'S

Image
Sorting Objects Most PowerShell Cmdlets produce objects in a deterministic fashion, which means that they tend to produce objects in the same order every time you run the command. Both service and process, for example, are listed in alphabetical order by name. What if we want to change that. For example, we want to display a list of processes, which is the biggest consumers of Virtual Memory (VM) at the top of the list. For this, we need to re-order that list of objects based on VM property. PowerShell provides a simple Cmdlet, Sort-Object, which does exactly that: Get-Process | Sort-Object -property VM We're hoping that you'll follow this blog and try to run all the given commands to test it yourself. That command isn't exactly what we wanted. It did a sort on VM, but it did so in ascending order, with the largest values at the bottom of the list. By reading help for the sort-object, we see that it has a -descending parameter...

DAY-1 : POWERSHELL…WHAT IT IS>>>AND WHY

Image
    POWERSHELL …WHAT IT IS>>>AND WHY                                                                                                                                                                                                                                        ANKIT SHARMA For normal computer users it is a useless…..but listen, for an IT administrators it is a great standard comm...