Posts

Showing posts with the label PowerShell Objects

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

Image
Objects: Data By Another Name Use of Objects in PowerShell sometimes can be one of the most confusing elements but at the same time, it's the also one of the most critical concepts, affecting everything you do in the shell. What are the Objects? Run a command Get-Process in PowerShell. You Should see a table with several columns, but those columns barely have the complete information about the processes. Each process object also has a machine name, main window handle, maximum working set, exit code and time, and a great deal of information. In fact, you'll find more than 60 pieces of information associated with a process. Now the question is, why did PowerShell show so few of them? The simple fact is that most of the things PowerShell can access offer more information than what will comfortably fit on the screen. When you run a command, such as Get-Process, Get-Service, or anything, PowerShell constructs a table containing all the inf...