All posts tagged: PowerShell-ism

ConvertTo-PowerShell: PowerShell versus “other” scripting examples – Part 5: List 20 largest files

In today’s post, I will show an example script to retrieve a 20 largest files on C: drive. As usual, we will first look at the VbScript example and then see a PowerShell “one-liner”. VBScript

This VBScript uses log parser 2.2 COM object to make it easy and faster to get a list of largest files. It would be very tough to achieve this without log parser and using file system object. So, to be able to run this script, you must have log parser 2.2 installed on your system. Now, let us see how we can do that in PowerShell without requiring log parser and in just one command.

This is it. It is simple and concise. That is the Power of PowerShell.

ConvertTo-PowerShell: PowerShell versus “other” scripting examples – Part 4: Renaming files

Continuing this series of posts on PowerShell-ism, today, I will show a VBScript example and then convert it to a PowerShell one-liner. So, this script was my response to a question on the scripting guys forum. This script reads a text file containing tab delimited information and then uses the lines in the text file to rename a bunch of files. So, let us jump in. VBScript


This is it. I am sure you must be seeing the benefits of “converting” to PowerShell-ism by now.

ConvertTo-PowerShell: PowerShell versus “other” scripting examples – Part 3

Yesterday, I mentioned that PowerShell can take care of many important aspects like formatting output, etc and let you focus on the core aspects of what you want to achieve using a PowerShell script. In today’s post I will show an example to demonstrate this.   In this example, let us first look at a VBScript that gets a list of processes running on a set of remote computers and then we willl look at how PowerShell simplifies that.   VBScript  

Look at this VBScript. We loop through the contents of a text file, pickup each line (a server name) as strComputer, connect to the computer using WMI, retrieve a list of processes and then finally, iterate through the process object to display list of properties we need. Many steps involved in doing this that require you to have knowledge of many others such as WMI. The output formatting is done by us. Here we just pickup three properties of a process object. Imagine writing up Wscript.Echo statement for all the 20+ object properties. Also, we are not really formatting …

ConvertTo-PowerShell: PowerShell versus “other” scripting examples – Part 2

Please take a look at part 1 to understand why I started this series of articles.  In this post, I will show another example from the scripting guys forum. Again, this is a PowerShell one-liner to do the job of 30 lines of VBScript. What this script does is real simple. It just creates a folder with current time as name and inside that a folder with current date as name. Simple..right.!?       VBScript      

As you see in the above example, we spend more time creating objects, parsing date / time, etc. Where as, the core requirement is a simple CreateFolder method.       PowerShell  

It looks simple in PowerShell because of it’s implementation of .NET based self-describing object model. We check if a folder with a specified name exists and if not, we create the folder and pipe the resulting object to ForEach-Object and use the CreateSubDirectory method to create a folder underneath it.     PowerShell lets you concentrate on what you needs to achieve and it takes care of remaining aspects like formatting, etc. More on this in the …

ConvertTo-PowerShell: PowerShell versus “other” scripting examples – Part 1

On the scripting guys forum and various other places, I still see various people asking for VBScript examples or DOS batch file examples for achieving various things on Windows OS. I — almost every time (unintentionally) — provided a PowerShell example even when the person’s preference was VBScript or DOS batch. I see many people shying away from Windows PowerShell thinking that the language is too complex. It is actually not “so” complex. I agree that it takes time to get used to it.  Windows PowerShell is not just an alternative to other scripting languages on Windows platform. If you think it is, time for you to change that thought process. In my opinion, being an alternative scripting language is a good side-effect of being the most powerful scripting platform. It is time people start using PowerShell or convert to the religion called PowerShell-ism.  One way to showcase the power of PowerShell is to show how easy it is to script it PowerShell and show how concise these scripts can be. So, that is the goal of this blog series. …