Press "Enter" to skip to content

Category: Powershell

Opening a Browser in Powershell

Robert Cain starts a process:

As part of my ArcaneBooks Project I described how to use the OpenLibrary Simple API to get book data.

In that post I also showed a way to bring up the webpage for an ISBN. I had a thought, why not build a function to add to the module to do that? This way a user would have an easy way to compare the output of the web API call to what the site holds.

In this post I’ll describe how to use the Start-Process cmdlet to open a target webpage.

Read on for the code to do this.

Comments closed

Comparing Two Objects in Powershell

Patrick Gruenauer sees which of these is not like the others:

In this short blog post, I will show you how to compare two PowerShell objects to find differences between them. I will also give you an example on how to create objects for testing purposes. Let’s dive in.

If you’re familiar with the diff command, you’ll have some idea here. One advantage to Compare-Object, however, is that Powershell is dealing with objects rather than strings, allowing for more complex comparison scenarios assuming your objects are set up for it.

Comments closed

Elapsed Timers in Powershell

Robert Cain keeps track of time:

I’m still working on my documentation for my ArcaneBooks project, but wanted to have something for you to read this week, so decided to show you how to create an elapsed timer in PowerShell.

It can be helpful to determine how long a process runs in PowerShell. You can use it to determine what parts of code may need to be optimized, or gather metrics around your functions.

This is the same stopwatch operation which is available in .NET generally, so if you’re using C# or F#, it’s the same basic process.

Comments closed

Building an About Topic Help File in Powershell

Robert Cain teaches us about teaching others about something:

In my previous post, Fun With PowerShell – Authoring Help, I covered how to author comment based help for your functions.

In addition to help for your functions, it’s also possible to write about_ help. PowerShell itself contains many about topics for PowerShell itself.

These about topics are designed to provide further information for your users, information that may not fit into the confines of a functions help. These texts can be as long as you need.

I will say that the Powershell team nailed it with the way they implemented help.

Comments closed

Adding Help to Your Powershell Code

Robert Cain helps those who help themselves:

Having good help is vital to the construction of a module. It explains not only how to use a function, but the purpose of the module and even more.

Naturally I’ve included good help text in the ArcaneBooks module, but as I was going over the construction of the ArcaneBooks module I realized I’d not written about how to write help in PowerShell. So in this post and the next I’ll address this very topic.

Read on for Robert’s thoughts on the topic, including standard ways to add content comments so Powershell’s built-in Get-Help cmdlet works for you.

Comments closed

Documenting Group Policy Objects with Powershell

Patrick Gruenauer builds a report:

Active Directory Group Policies (GPO) enables you to control user and computer settings. It is important to document them. In this blog post I am going to show you two PowerShell commands which create a GPO HTML Report. Let’s dive in.

To store all GPO Settings from all GPOs in one file run this command. Don’t forget to provide your domain name and the path of the report file.

Click through for that code snippet, as well as another one which builds an HTML report for each GPO.

Comments closed

Parsing Library of Congress Data with Powershell

Robert Cain continues a series on books:

For this demo, we’ll be using an LCCN of 54-9698Elements of radio servicing by William Marcus. When we call the web API URL in our web browser, we get the following data.

Click through for the results of the API call, which happen to be a blob of XML data. Robert shows how to get that data programmatically, then how to shred it into what he needs.

Comments closed

Finding Special Characters in Powershell

Patrick Gruenauer looks for special characters:

Sometimes special characters are a nuisance. If you are trying to create some user accounts in on-premise or cloud environments, you should avoid special characters in usernames. In this blog post I will show how to find this special characters.

Click through for a regular expression-based approach, which also allows you to exclude special but not special enough characters.

Comments closed

Building Strings in Powershell with StringBuilder

Robert Cain takes to a .NET class to build some strings:

As I was creating the next post in my ArcaneBooks series, I realized I had not written about the StringBuilder class. As the code in my ArcaneBooks module relies on it in several places, I thought it best to add a new post to my Fun With PowerShell series explaining how to use it before continuing.

It’s a common need in any language, and PowerShell is no exception, to need to add more text to an existing string.

Read on to understand why the StringBuilder class exists and how to use it. If you’re doing a lot of string manipulation, particularly of large strings in loops, this can provide a noticeable performance impact.

Comments closed

Building a Wordle Solver in Powershell and T-SQL

Shane O’Neill takes this T-SQL Tuesday to heart:

I got swept up in that wave for a while in the same way I got swept up in the other trends of my time, like Pokemon, Sodoku, and Angry Birds.

Eventually, I stopped when I found a PowerShell script by Kieran Walsh ( github | twitter ) where you could narrow down to the correct answer by putting in the results of your guess each round.

This hack led to me realising how much time I was spending on Wordle and that I should stop, much like I did with Pokemon, Sodoku, and Angry Birds.

So, what better thing to do than to try and recreate that PowerShell script in T-SQL

And given Shane’s time restriction, I’d say the end result is a good one.

Comments closed