Press "Enter" to skip to content

Category: Powershell

Looping through bcp Calls in Powershell

Peter Schott needs to perform a series of bulk inserts:

Sometimes you need to extract a large number of tables into some other format. I’ve written about BCP earlier as a quick option to move data around, but what if you need a delimited text file or a way to repeat the calls without too much trouble across a set of servers? I had this come up recently and wrote up a combination of PowerShell, the sqlserver module, and the bcp.exe tool to allow for a variety of extract types and also, importantly, ensure that we get header data with those extracts in case we need them to pull in to another process. This is doable without the header piece, but many processes (and humans) expect some sort of header data. Thus – a slightly expanded process.

Click through for a script and an explanation of the process.

Leave a Comment

Scraping SQL Server Version Updates

Rod Edwards scrapes patch information:

(just for info, i’ve always refer to the SQL Server Version List (https://sqlserverbuilds.blogspot.com) as Blogspot for some reason)

Doesn’t take long, but it would be nice to not have to bother at all, and I don’t mean by moving everything to the cloud and let MS handle it either before anyone says it. 🙂

The details are just websites, so the html is just plain text, AND the awesome people who provide Blogspot also add the details to a publicly shared google doc, in multiple formats, legends.

So what can we do to make our lives even easier. How about downloading/scraping all of the details that you might ever need, and dropping them into tables somewhere? So when its in SQL, you can then choose to trigger off that however you like?

Read on to learn how.

Leave a Comment

Finding Empty Attributes in Powershell

Patrick Gruenauer looks for what’s missing:

We are often looking for attributes, but what about the empty attributes? How can I find out if an attribute is empty? That is the focus of this article. I will show a practical example of how to find these empty attributes.

Let’s start with how to find attributes which are NOT empty. The following code retrieves all svchost process Attributes which have a value.

Read on for the pipeline to see which attributes have a value, followed by a similar pipeline to find missing values, as well as one practical use case for why you might use this.

Leave a Comment

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.

Comments closed

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.

Comments closed

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.

Comments closed

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