Category Archives: Powershell

Check If SQL Table Exists Using Powershell

      No Comments on Check If SQL Table Exists Using Powershell

Another common request for DBA’s is to search for or validate that certain tables or other objects exist and in what database. This post is a follow-up to our “Check If Database Exists Using Powershell” post where we search look for a database remotely using the “invoke-sqlcmd” commandlet. Note: This… Read more »

Use Powershell To Get-service Status On Remote Computer

Powershell offers a few cmdlets targeted to managing a remote server and setting the service state as well as the startup. We will run through a few examples of getting the service information and than setting their state as well as the startup option. These scripts requires Administrator access to… Read more »

Use Powershell to Compare Dates Without Time | get-date

Working in Powershell with dates, time and time zones is critical if you have data or automated processes that reference different geographical areas. Understanding how to compare these dates with and without a time value can mean the difference between an incorrect report or failing processes. We have written before… Read more »

Get SQL Server Instance Name Using PowerShell | Details

We can use a commandlet called get-sqlinstance to quickly query an existing SQL instance on a remote server for more information. The administrator often needs to inventory the server environment and that includes identifying the SQL servers as well as all of the instances. Another useful commandlet for SQL Server… Read more »

Use Powershell To Remove Everything Before or After A Character

Working with strings is important when handling automation processes especially regarding server names and the SQL Server instances. Administrators define their own naming conventions and usually stay away from unique characters in the string. With SQL Server we have a slash “\” that is required to define the SQL instance… Read more »

Get Active Directory Group Members Using Powershell and SQL Server

Using Active Directory Groups (AD) for SQL Server authentication makes managing access permissions easy. Instead of managing individual login permissions the DBA can recommend using some AD groups that can contain many users and the login and permissions are assigned only one time. I have limited knowledge of Active Directory… Read more »

Use Powershell To Combine Datatable And Schema Using Merge

The more often you work with datatables in Powershell the more opportunities appear where you can utilize more features. We will look at the Merge method as well as updating data and adding new columns to an existing datatable. For this example we will be using the “WideWorldImporters” (WWI) database… Read more »

Using Powershell Check For Pending Reboot and Last Restart on Remote Computer

We want to check for a pending restart. If a server is awaiting a reboot before attempting to to install new software or make OS changes. These powershell examples will help with checking the last reboot date and time as well as return a Yes and No if it is… Read more »

Find All SQL Server Instances On The Network Using Powershell

Searching for and cataloging the SQL server instances on your network is a key part of Administration. Powershell offers some quick and simple methods to find servers base on the their name or description in Active Directory. We can use the Powershell module to collect these servers and add them… Read more »