Wednesday, May 8, 2024
HomePowershellAutomation Selections • The Lonely Administrator

Automation Selections • The Lonely Administrator


This submit is an up to date reprint from an article printed to my premium PowerShell e-newsletter Behind the PowerShell Pipeline obtainable on Substack. Subscribers obtain 6-8 articles like this a month delivered to their inbox or obtainable on the Substack app. I hope you’ll take into account subscribing. Trial subscriptions can be found.

I’ve been scripting and automating issues because the days of DOS 3.3, starting with batch information. It at all times felt like magic. I might solid a attraction just by typing a couple of characters on a keyboard. Naturally, my magic abilities went from batch information to VBScript to PowerShell. All through all of it, I’ve additionally had an inside determination tree concerning automation. Through the years, I’ve seen IT professionals new to scripting and automation needlessly wrestle. Usually it is because of a deficiency of their determination tree. In the present day, I assumed I’d assist you nurture yours.

Is it Well worth the Funding?

That is the primary query you need to at all times ask when contemplating a brand new automation mission. I’m certain you’ve all heard the phrase, “Simply because you are able to do one thing doesn’t imply you need to.” That is very true with regards to PowerShell.

PowerShell makes it simple to automate duties. Ideally, you utilize PowerShell and automation to deal with repetitive duties, particularly unglamorous duties that should be carried out usually. Any PowerShell resolution that you just develop would require an funding. At a minimal, you’re investing time to put in writing your code. That is time you’re taking away from different work. Relying on the duty, chances are you’ll must spend money on extra academic materials corresponding to books or courseware.

As you take into account a brand new PowerShell mission, you want to have the ability to estimate how a lot time you have to. This turns into simpler as you acquire expertise. And with expertise, you’ll additionally discover you are able to do extra in much less time. It is advisable to weigh the time required in opposition to the time saved. For instance, I in all probability wouldn’t take the time to construct tooling round enabling the Lively Listing Recycle Bin characteristic. Sure, you utilize PowerShell, however this isn’t an ongoing job. However I’d create a PowerShell software round resetting a person’s password.

In fact, there are exceptions. You might wish to develop a PowerShell resolution as a method of bettering and increasing your scripting abilities. I’ve been identified to joke about spending a day writing a PowerShell operate that saves me a couple of seconds. However, over the course of a yr, these seconds add up. And after I’m completed, I’ve more than likely realized one thing that I can use in future initiatives. In these conditions, I’m utilizing a distinct metric to justify my funding. It isn’t the time I’m saving however the studying course of that warrants my time.

The underside line is it’s good to take a look at the duty at hand, take into account how a lot of an funding it can require, and calculate the cost-benefit ratio. Your time is proscribed and invaluable so use it correctly.

Can It Be Scripted?

You additionally want to think about in the event you may even automate the duty at hand. I’ve seen many requests for automation assist through the years that boggle my thoughts. This can be a case the place you have to perceive PowerShell and acknowledge what it’s designed to do and, extra importantly, what it will possibly’t. Here’s a shortlist.

  • PowerShell just isn’t designed to click on via an internet site.
  • It’s not designed to run ON an internet site.
  • It isn’t designed to handle a person’s Outlook inbox.
  • PowerShell isn’t supposed to handle desktop functions.

PowerShell was designed as a administration engine, which initially meant Home windows servers. It has since been developed to incorporate cross-platform server administration and cloud-based service administration. I’ve by no means thought of PowerShell a very good software for managing an finish person’s desktop or consumer expertise.

I acknowledge that there you may have the ability to use PowerShell for a few of these duties. However more than likely, it can require very refined scripting, if not outright hacks, that border on .NET improvement.

Are There Higher Options?

Simply because PowerShell is at your disposal doesn’t imply it’s the proper software on your automation job. As an alternative of attempting to cobble collectively PowerShell scripts to handle a consumer desktop, you need to use Group Coverage. That may be a software designed for that job. Do you actually must automate a GUI interplay? Take into account a software like AutoIt. There’s virtually a couple of technique to do one thing in Home windows. Granted, chances are you’ll want to do a little analysis to find alternate options.

I bear in mind years in the past getting a request for assist with VBScript. The IT Professional was new to scripting however needed to put in writing a script utilizing WMI to set file permissions. That is one thing that not even I’d have needed to do. A better option can be utilizing a software designed for managing file permissions like cacls.exe or icacls.exe. Even at this time, utilizing PowerShell to handle file permissions in Home windows just isn’t a trivial job. It might be simply as simple to put in writing an old style batch file utilizing one in all these legacy, however nonetheless helpful utilities.

That stated, utilizing PowerShell could be justified even when there’s an alternate. Assuming, after all, that the duty at hand will be completed with PowerShell. If it’s good to combine extra performance like help for -Whatif, alternate credentials, or logging, writing a PowerShell resolution could also be value your time. Assuming you’ve already carried out the cost-benefit evaluation, I really useful earlier.

PowerShell Isn’t All the time the Reply

By now, I hope you aren’t too stunned for me to inform you that PowerShell isn’t at all times the best software for the job or the legacy different is simply as legitimate. I’m extra more likely to run route as an alternative of Get-NetRoute. That is very true after I solely wish to get a fast take a look at one thing.

It’s simply as simple to run:

icacls .knowledge.txt

as it’s to run:

get-acl .knowledge.txt | select-object -ExpandProperty AccessToString

Let’s say you wish to handle energy settings on a neighborhood pc. The CLI software powercfg.exe goes to be your greatest wager. Or it’s good to handle native safety settings. PowerShell doesn’t provide any out-the-box options. You’ll more than likely want to make use of secedit.exe. However bear in mind, nothing is stopping you from wrapping these legacy instruments in PowerShell. Secedit.exe doesn’t have a -WhatIf equal, however you may write a PowerShell operate that does.

You Resolve

I hope you don’t assume I’m advocating you solely use PowerShell for particular instances. That’s not true in any respect. I’d encourage you to at all times be fascinated by how you may use PowerShell to make your job simpler. Nonetheless, it’s good to stay open to the chance that PowerShell will not be the best software for the job. And even whether it is, is it well worth the funding? Earlier than you dive into a brand new scripting mission, take a minimum of a second to assume and make a aware determination. I hope this text will assist you make the best alternative. On the very least, I belief it is going to be an knowledgeable determination.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments