Press "Enter" to skip to content

Category: Powershell

Measuring Bandwidth with Powershell

Patrick Gruenauer checks download speed:

Short explanation: A file will be downloaded from my homepage. It’s a video about Powershell Profiles in German language. During the download of the file the process is measured with the Measure-Command cmdlet. At the end we get the final result and the time it took to download the file.

You can, of course, change the file location to whatever makes sense, but it’s nice to have something handy and not need to go to any websites for a speed test.

Comments closed

Running SqlBulkCopy in Parallel from Powershell

Jose Manuel Jurado Diaz has a script for us:

Today, we encountered an interesting service request of attempting to reduce the load times for 100,000 records from a table with 97 varchar(320) fields in an Azure SQL HyperScale database. Following, I would like to share my lessons learned here.

The idea is to split in different concurrent process the execution of multiples SqlBulkCopy. In this case, we are going to split this process in 5 processes running in parallel inserting 20,000 rows, let’s try to know the total size. 

Read on for the script, as well as a rough idea of how long it’ll take inserting into an Azure SQL DB Hyperscale instance.

Comments closed

Implementing Multiple Retries in Powershell

Jose Manuel Jurado Diaz has a script for us:

We often encounter support cases where our customers leave the query execution timeout value at its default. In certain situations, we may find that when this value is reached, the application reports an error and does not continue. In this case, I would like to share an example implemented in PowerShell that allows incrementing the command timeout value up to 5 attempts, with a 5-second margin in each operation.

My recommendation here would be to use Polly instead, as it built in support for exponential backoff and more complex retry logic. Adam Driscoll has a Powershell wrapper called pspolly, which may also prove helpful.

Comments closed

Code Signing on an Executable

Gianluca Sartori takes us through the process of signing our own executables:

Why does happen with some files and doesn’t happen with the Chrome installer or Acrobat reader? Because those setup kits are signed with a certificate from Google and Adobe, released by a certification authority that checks that Google is actually Google and not a disgruntled random guy pretending to be Google.

This means you can sign your code too, you just need to get a code signing certificate from a certification authority and they will be happy to give you one in exchange for money.

Click through for the step-by-step demonstration and a Powershell script to perform the signing.

Comments closed

Automating Azure SQL DB Maintenance Tasks

Tracy Boggiano reminds us that we still need to administer Azure SQL DB databases:

I’ve been using Azure SQL Database for quite some while and have set up it in many various ways to run Ola’s Index Optimize and Statistics Updates on them.  All of these have seemed way too complicated probably because I was setting them up once, not again for several more months or a year.  Well with my new job, I have over 20 subscriptions with various Azure SQL Servers in them so it was time to streamline at least knowing what I was doing.  No matter what I googled on the Internet I never did find one source that walked me step by step on each thing I needed to know to set this up.  So hopefully this will cover everything.

Click through for the step-by-step process.

Comments closed

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