PowerShell, Scripting
comment 1

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.!?      


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.      


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 next post.

Filed under: PowerShell, Scripting


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.