Powershell is a useful skill to have at the workplace and at home, and learning a handful of PowerShell commands can make your life a lot easier. A few years ago I didn’t use it much, especially at work because I was not too comfortable with it. I was more comfortable in just using the command-line. I Eventually, started playing around with it and I noticed that PowerShell also had a lot of the commands from LINUX built in. An example of a command is the ls
command, which is the same as the dir
command in Windows.

Powershell Terminology
The dir
command was only used in Windows, and never Linux. In Linux the command ls
is used instead. They both list the directory structure. PowerShell uses get-childitem
for the same command. While both commands may have their separate options, their basic output was the same. The creators for get-childitem
cmdlet added an alias that allowed you to use either ‘dir’, or ‘ls’, and it would interpret it as running the ‘get-childitem’ command. Therefor the output is the same. Although this article isn’t going to teach you the basics of PowerShell, it is important to understand that everything returned to a PowerShell command is an object. Which really means, we can do a lot more with the data returned — it isn’t just a string. We can pass what we are returned, to another PowerShell command.
Over the last few years, I ended up using PowerShell a lot to manipulate and move files – especially at work. I have even used it for creating a GUI for the application! Here I will list some important commands I used (almost daily), and define what they do. I will also use important options for each command and define them as I use them. As far as powershell goes, you need to at least know the basic functionality. I will try to elaborate on newer concepts but please remember, this is not an article for complete newbies — having basic understanding of most any programming language should suffice.
Get-childitem
Get-childitem may be the most used command (cmdlet) that PowerShell has for viewing and manipulating files. It allows you to view the contents in the current directory:
Now, if you run the command dir
or the command ls
, you will get the same exact output, because (as stated earlier) ‘get-childitem’ is just another way of typing dir
in windows or ls
in Linux. But this article isn’t about Windows, or Linux, but for both — you can install powershell on most any Linux or Windows machine. Matter of fact: if you’re running Windows, you probably already have it.
Powershell Version
To see if you have it, go into the terminal or command line, and type in $PSVersionTable
Here is an image of the output:

Most of our commands or scripts will generally start with Get-childitem
, because it give us a list of files plus the directory. We can filter them further by taking the input and piping it to another command. For instance the command Where (?)
and the command For-Each (%)
. For example, if we want to return only folders, we can alter the command and send our output as input to the command with the pipe character(|):
get-childitem -recurse | for-each {$_.psiscontainer}
We can also write the same command as:
get-childitem -recurse | ? {$_.psiscontainer}
Briefly, this returns:
config images
What this command is doing is, running the get-childitem command and passing each item as an object, allowing you to refer to its properties with the next command. So then, the for-each command, first PowerShell checks if it’s a file or a folder. If it’s a folder (isContainer), it will return it in the output, or next command after the pipe, otherwise discard it. By default, PowerShell outputs the final command to the terminal window.
We can also use the command for some important tasks. Lets say you need to get the count of file extensions and sort by count.
get-childitem -recurse|? {! $_.psiscontainer} | group extension -noelement| sort count -desc
This will output the following:

As you can see, it listed the count, and file extension for each of the extensions. This can be useful when you need to view all the natives, or do a count of images.
MORE COMING…
0 Comments