Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

So you need to write a PowerShell script

Posted on July 7, 2014

lightbulb-idea So...you have decided to write a PowerShell script or have at least identified a need. What do you do first? If you say "Google or Bing", I'd say you are wrong. In my opinion, when you are developing a PowerShell script, searching for an existing script is not the first step. Sure, you will likely find something, but....

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

There are many online sources of PowerShell scripts and code samples. However, from my experience the quality is all over the board. Sure, you might find a great example. But unless you have a great deal of PowerShell experience, how will you judge? Sadly, many script and code samples I see don't follow community accepted best practices, don't follow the PowerShell paradigm or are simply bad scripts. There is also absolutely no guarantee that the script or code sample you download will work correctly (and safely) in your environment.

Personally, I would recommend that you open your script editor and start laying out a series of comments about what it is that you need to accomplish. If you are using the ISE you might even use regions to outline your script. This task helps your organize your work, and when you are finished, the script is documented? All you have to do is write the code to fulfill the comments. Yes, that might be difficult and maybe even a little time consuming at first, but that's the point. You will be learning much more than by simply copy and pasting something of dubious quality you found online. Even more importantly, you will be developing something that you know will work in your environment.

Get stuck? Then sure, look online to find examples of how someone used a particular cmdlet or function. But try to find several examples and "average" them out. Perhaps even better would be to post in the forums at PowerShell.org and ask for specific help on a sticky problem. You'll likely get several responses. And knowing the quality of the average PowerShell.org forum member, I'd feel very comfortable with their responses.

Over time, as you gain more PowerShell experience, you will be better able to assess the quality of online PowerShell scripts and samples. I still think you should develop on your own from scratch, but I also think you'll find the process goes much faster.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

4 thoughts on “So you need to write a PowerShell script”

  1. Jeffery Hicks says:
    July 7, 2014 at 2:09 pm

    One final thought: I always stress that you must test everything in a non-production environment. Especially if you are running someone else’s code.

  2. Jeffery Hicks says:
    July 7, 2014 at 3:30 pm

    I also realized that if you are going to download code, you might want a copy of my script profiler. https://jdhitsolutions.com/blog/2014/01/updated-powershell-script-profiler/

    1. Philip Tomson (Avalon-Zone) says:
      July 8, 2014 at 1:40 am

      Before coding I always draw a complete flowchart with MS Visio. This is time consuming at first but you get a really good overview of what will be done and how it will be done and finally this step speeds up the coding phase a lot.

      1. Jeffery Hicks says:
        July 8, 2014 at 8:01 am

        For complex projects I can see where that would be of great value. Especially in a corporate environment because now you have background documentation for “the next guy.”

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d