Get-member
cmdlet. Now you can see all the different properties and Methods that exist on the Get-Service
cmdlets. There are other member types also present. But we will focus only on the property and method.
Get-ChildItem
cmdlet is going to list out all the contents of the current directory. Now, we can use the length property of the file to filter out the file list that displayed. We can do this using the Where-Object
cmdlet, which filters objects based on a specified condition. Here’s how we can use it:
Get-ChildItem
gets a list of files, and then the pipeline passes each file object to Where-Object
. The $_
variable represents the current object in the pipeline, and we access the Length property using $_.Length
. We compare this to 5MB using the -gt
(greater than) operator.
We can also use object properties to group data in pipelines. For example, suppose we have a list of files, and we want to group them by their file extensions. We can use the Group-Object
cmdlet to do this, like so:
Get-ChildItem
gets a list of files, and then the pipeline groups the files by their Extension property. The resulting output shows the number of files in each group.
We can also use object properties to sort data in pipelines. We can use the Sort-Object
cmdlet to do this, like so:
Select-Object
cmdlet to display only the name and length.
Copy-Item
cmdlet to make a copy of that file.
To access an object’s methods, you can use dot notation. For example, if you want to use the Copy-Item
method on an object, you can use the following syntax: