Press "Enter" to skip to content

Category: Powershell

Azure Elastic Jobs to Run Powershell and T-SQL

Josephine Bush kicks off a job:

I’ve covered how to create Elastic Jobs in the portal (this one is important to read if you aren’t familiar with elastic jobs already), with Terraform, and with Bicep. Now, I’ll cover how to create them and their associated objects with PowerShell. Don’t do this in prod to start. Always test in a lower environment first.

Click through for the process, as well as the script.

Leave a Comment

Moving SQL Server Database Files

Vlad Drumea makes a move:

This post demos a script I put together to help move SQL Server database files to another drive and folder by generating PowerShell and T-SQL commands.

I’ve decided to make this script for situations where installing the dbatools PowerShell module wouldn’t be possible.
Otherwise, I highly recommend using dbatools’ Move-DbaDbFile command.

Click through for the script, and I second Vlad’s recommendation of dbatools for this kind of effort.

Leave a Comment

Multi-Storage Array Database Snapshots in SQL Server

Anthony Nocentino continues a series:

In this post, the fourth in our series, I want to share an example demonstrating SQL Server 2022’s T-SQL Snapshot Backup feature in a scenario where a database spans multiple storage arrays. If you’re dealing with multi-array environments, you’ll appreciate how this technique freezes database write I/O to take coordinated snapshots across volumes on two FlashArrays. In this post, I’ll walk you through the process, point out some of the script’s key elements, and show you how long the write I/O pause takes.

Click through to learn how it all works when you have a database spanning multiple volumes.

Leave a Comment

Building the Scaffolding of a Powershell Module

Adam Bertram has a series on creating Powershell modules:

In this guide, we’ll create a PowerShell module for gathering computer hardware information. This module will help system administrators collect and report on memory, storage, and processor details across multiple systems.

Our module will feature:

  • Functions to gather specific hardware information
  • Remote system support using PowerShell sessions
  • Standardized output format for consistent reporting

Click through for the article.

Comments closed

Writing Loops in Powershell

Adam Bertram is spinning in circles:

One of PowerShell’s key features is its ability to loop through data collections, enabling you to execute a code block repeatedly.

In this tutorial, we will explore three fundamental loop structures in PowerShell: foreachfor, and do loops.

By the end of this tutorial, you will have a solid understanding of how to use these loops to handle repetitive tasks and process collections of data more effectively.

Click through for the tutorial.

Comments closed

Calling IFTTT from Powershell

Denny Cherry triggers an action:

Sometimes, you want/need to have PowerShell do an action, but it’s hard to do through PowerShell, or it can’t be done at all. If the website If This Then That (IFTTT) can do it instead, you can still do it through PowerShell, with a little extra work. The way to do this will be to call a webhook on an IFTTT Applet and pass the information you need to send to the third-party service. A great example of this would be if you need to automate posting a new post to FaceBook. Posting to Facebook is shockingly hard as you have to write all the pieces to post to Facebook manually, and there’s no current way to post to Facebook via PowerShell. However, you can call an IFTTT Action and have that action do the actual posting to Facebook for you.

Click through for a generic form of the process.

Comments closed

Cmdlets vs Functions in Powershell

Adam Bertram differentiates the two:

Whenever you execute or run anything in PowerShell, you’re running a “command.” A command is an informal term for executable code, which can be a built-in PowerShell cmdlet, a custom function, or even an object method.

Cmdlets are compiled executable code provided by Microsoft, created in a language like C#, compiled, and added to a PowerShell module by software developers. Functions, on the other hand, are created directly in PowerShell by users. Although functions and cmdlets are technically different, they can be thought of as similar when you’re starting out.

Read on for more information, including a demo. I normally call them all cmdlets, but apparently I’ve been doing it wrong all this time.

Comments closed

Restoring a Database in Three Separate Ways

I have a new video:

In this video, I show how to restore SQL Server databases using SQL Server Management Studio, T-SQL, and the dbatools PowerShell module.

Originally, I had plans on covering SSMS + T-SQL in one video, and then dbatools in a second. Then I decided, well, why not just cover both of them in the same video? And this is how we get to half-hour long videos.

Comments closed