dbachecks – dbatools https://dbatools.io/ the community's sql powershell module Sat, 25 Aug 2018 18:07:02 +0000 en-US hourly 1 https://wordpress.org/?v=5.3.4 https://dbatools.io/wp-content/uploads/2016/05/dbatools.png?fit=32%2C32&ssl=1 dbachecks – dbatools https://dbatools.io/ 32 32 111052036 PowerShell Precon at PASS Summit 2018 https://dbatools.io/psprecon/ https://dbatools.io/psprecon/#respond Thu, 12 Apr 2018 14:01:09 +0000 https://dbatools.io/?p=7680 Congrats to our teammate Rob Sewell! Rob was invited by PASS to present about PowerShell at PASS Summit 2018 on Tuesday, November 6 2018.

In his day-long session, Rob will talk about a variety of super interesting subjects including: dbachecks, PowerShell module-making, GitHub, VSTS, and dbatools. Rob is a vibrant, knowledgeable speaker and I can’t recommend this precon enough! I learn a ton every time that Rob and I present together.

Professional and Proficient PowerShell

Professional and Proficient PowerShell: From Writing Scripts to Developing Solutions

DBA’s are seeing the benefit of using PowerShell to automate away the mundane. A modern data professional needs to be able to interact with multiple technologies and learning PowerShell increases your ability to do that and your usefulness to your company.

At the end of this fun filled day with Rob, a former SQL Server DBA turned professional automator, you will be much more confident in being able to approach any task with PowerShell and you will leave with all of the code and demos. You can even follow along if you bring a laptop with an instance of SQL Server installed.

  • How to learn how to interact with any technology using PowerShell
  • Understanding the syntax
  • The importance of Get-Help and how PowerShell enables you to help yourself
  • Why to write your own Modules and how to make them available to all of your team
  • A quick automated method to creating your module framework
  • Unit testing and debugging your code
  • How to continuously deliver changes to your PowerShell modules using GitHub and VSTS
  • Tips and tricks for script writing with the popular open-source community dbatools module
  • How to validate your SQL Server estate with PowerShell
  • Advanced SQL Server Agent and PowerShell management

We will have a lot of fun along the way and you will return to work with a lot of ideas, samples and better habits to become a PowerShell ninja and save yourself and your organisation time and effort.

Register now

To register, visit the shortlink sqlps.io/precon

- Chrissy

]]>
https://dbatools.io/psprecon/feed/ 0 7680
dbachecks commands https://dbatools.io/dbachecks-commands/ https://dbatools.io/dbachecks-commands/#respond Thu, 22 Feb 2018 12:01:38 +0000 https://dbatools.io/?p=7143 dbachecks is a new PowerShell module from the SQL Server Community! For more information, read introducing dbachecks.

As of version v1.0, dbachecks contains 15 commands. This article provides an overview of these commands. Rob Sewell offers a fantastic deep-dive article that explains the commands below in greater depth.

Usage

Usage can be approached in two ways:

Run directly from the command line

As simple as Invoke-DbcCheck -SqlInstance sqlprod01 -Checks SuspectPage, LastBackup

Schedule checks

Command line execution is good in a pinch, but ongoing checks are the ultimate goal. In order to do this, you can do the following:

  • Set your desired configuration
    Configs can be set for specific environments like Production, Test or Development or for an application, like SharePoint or a custom-built app
  • Export your configuration
    Export your environment or application configuration so that it can be easily imported by your scheduled task
  • Schedule checks using Task Scheduler or SQL Server Agent
    I personally prefer SQL Server Agent
  • Get notified via email or load up in Power BI
    Since the output of Invoke-DbcCheck is a PowerShell object, you can extend responses and notifications any way you wish. We provide two built-in ways.

Whichever approach you use, the commands below will help you easily accomplish validation of your environment.

Primary commands

Invoke-DbcCheck

All checks are performed using Invoke-DbcCheck. This command is basically a wrapper for Invoke-Pester. This means that supported Invoke-Pester parameters work against Invoke-DbcCheck, plus a few bonus parameters.

In this module, a “Check” is synonymous with a “Tag” in Pester. So you can Invoke-DbcCheck and specify a Check that you want to run. You can see a list of the available Checks with Get-DbcCheck.

We also made it convenient to run groups of checks. So LastBackup will run LastFullBackup, LastDiffBackup and LastLogBackup.

Get-DbcCheck

This command lists all checks, check groups along with their required server type, either SqlInstance or ComputerName.

Set-DbcConfig

dbachecks comes with its own configuration system! This allows you to set values that are required for your environments. We set reasonable defaults, but your requirements may vary, especially between production and test/dev.

What are reasonable defaults? Well for instance, out of the box, dbachecks tests to ensure that log backups have been taken within the last 15 minutes. You may want this to be 60 minutes instead. To set this new value, run the following:

Set-DbcConfig -Name policy.backup.logmaxminutes -Value 60

Get-DbcConfig

Retrieves dbachecks configuration elements. You can run this command with or without a search pattern.

Piping Get-DbcConfig to Out-GridView will help make the results even more searchable.

Export-DbcConfig

Exports dbachecks configs to a json file to make it easier to modify or be used for specific configurations.

Rob’s deep-dive article mentioned above provides awesome insight as to how you can make the most of our Export/Import commands.

Import-DbcConfig

Imports dbachecks configs from a json file. The basic idea is that you set your configs, export them, then import them and run on a regular basis.

Send-DbcMailMessage

Converts Pester results and emails results formatted using ReportUnit. Basically wraps the Send-MailMessage cmdlet which sends an e-mail message from within Windows PowerShell.

Update-DbcPowerBiDataSource

Converts Pester results and exports file in the required format for launching the Power BI command. You will need to refresh the Power BI dashboard every time to see the new results. Basically, behind the hood it is running this:

Invoke-DbcCheck | ConvertTo-Json -Depth 3 | Out-File "$env:windir\temp\dbachecks.json"

Supports alternative paths.

Start-DbcPowerBi

Launches the included Power BI dashboard. You will need to refresh the Power BI dashboard every time to see the new results.

Start-DbcPowerBi also supports alternative paths, in the event, you specify a new path using Start-DbcPowerBi.

 

Supporting commands

Clear-DbcPowerBiDataSource

Clears the data source directory created by Update-DbcPowerBiDataSource (“C:\windows\temp\dbachecks*.json” by default). This command makes it easier to clean up data used by PowerBI via Start-DbcPowerBi.

Get-DbcConfigValue

Retrieves raw configuration values by name. Can be used to search the existing configuration list.

Get-DbcTagCollection

Retrieves a list of all available tags. Simplistic, similar to Get-Verb.

Invoke-DbcConfigFile

Opens the default location of the json config file for easy edits. Follow with Import-DbcConfig to import changes.

Save-DbcRequiredModules

Saves all required modules, including dbachecks, dbatools, Pester and PSFramework to a directory. Ideal for offline installs.

Update-DbcRequiredModules

Updates all required modules, including dbachecks.

 
This command reference will continue to be updated as we add more commands. The shortlink is dbachecks.io/commands.

- Chrissy

]]>
https://dbatools.io/dbachecks-commands/feed/ 0 7143
Installing dbachecks https://dbatools.io/installing-dbachecks/ https://dbatools.io/installing-dbachecks/#comments Thu, 22 Feb 2018 12:01:00 +0000 https://dbatools.io/?p=7099 dbachecks is a new open source module that allows the SQL Server community to crowdsource our checklists and easily test our environments 🤗 You can read more about it in our article introducing dbachecks – a new module from the dbatools team!

Requirements

The requirements for this module are a bit different than dbatools. dbatools supports PowerShell v3 but dbachecks supports PowerShell v4 and v5x. This allows us to take advantage of the faster, cooler syntax changes that became available in PowerShell v4. In addition, we have dependencies such as Pester that require a higher version.

This module does not support PowerShell v6 (Core).  

 

PowerShell

While we only require v4, we recommend using PowerShell v5.1 which runs on a variety of Windows Platforms including Windows 7 SP1. PowerShell v5.1 is faster and more secure since it has superior logging capabilities. Note that you only need a higher version of PowerShell on the workstation or server where you’ll be performing your checks.

PowerShell is installed as part of the “Windows Management Framework” or WMF.

Install and Configure WMF 5.1

 

Access to PowerShell Gallery

Online

Access to the PowerShell Gallery is required. Installing dbachecks will automatically install the required modules: dbatools, Pester and PSFramework.

Install-Module -Name dbachecks

For a step-by-step tutorial, check out walk-thru: installing modules from the powershell gallery.

Offline

If you are in a locked down environment, consider using an online workstation to save the required modules then copy them to one of the PowerShell paths ($env:PSModulePath) of your final destination.

Save-Module -Name dbachecks -Path C:\temp

This will also save the required modules. Note that it will say “installing dependent package” but it’s not installing, just saving.

For more information on installing modules offline, see the article, offline installs of dbatools.

 

Additional Modules

Required modules are automatically installed when you execute Install-Module dbachecks. Note that, like dbatools, dbachecks does not require SMO or SQL Server Management Studio to be installed.

dbatools

A majority of our checks use dbatools either for accessing local or remote Windows computers and SQL Servers.

Pester

dbachecks is basically one big Pester wrapper. Invoke-DbcCheck wraps Invoke-Pester and provides additional functionality for the SQL community, such as being able to specify -SqlServer and -ComputerName. You may notice, Pester calls them tests, but we refer to our tests as checks.

PSFramework

PSFramework, written by Friedrich Weinmann, provides easy Enterprise logging, messaging and configuration for PowerShell modules. We rely heavily on PSFramework both in dbatools (though have our custom version) and dbachecks.

 

SQL Server Agent

So you want to schedule checks using SQL Agent? Great idea! Remember that this module requires PowerShell version 4.0, which doesn’t always mesh with SQL Server’s PowerShell Job Step. To run dbachecks, we recommend you use CmdExec. You can read more at dbatools.io/agent.

If you do choose to use the PowerShell step, don’t forget to Set-Location somewhere outside of SQLSERVER:, otherwise, you’ll get errors similar to this

image

 

Troubleshooting

If you encounter any issues not described below, you can add an issue or join us in the #dbachecks channel on the SQL Server Community Slack.

 

Trouble updating Pester

Pester is built into Windows 10 and, in order to update it, needs to be “installed” once in a different way. If you encounter the error:

The required module ‘Pester’ is not loaded. Load the module or remove the module from ‘RequiredModules’

You will need to execute:

Install-Module Pester -SkipPublisherCheck -Force
Import-Module Pester -Force

 

Random Pester error

I’m the only one that appears to have experienced this so far, but if you encounter the error Unable to find type [Pester.OutputTypes], simply Import-Module Pester and it’ll work.

 

Trouble importing

If you run a command from dbachecks and receive the following error:

The command was found in the module ‘dbachecks’, but the command could not be loaded. For more information, run ‘Import-Module dbachecks’

You likely need to update one of the required modules. In order to ensure dbachecks works as expected, we have a minimum version requirement for dbatools, Pester and PSFramework. To update, you can run

Update-Module -Name dbachecks, dbatools, PSFramework, Pester

If this does not solve your issue, run Import-Module dbachecks manually.

Also, if dbachecks is loading properly and you just wanna update, you can use our built-in command Update-DbcRequiredModules or its easier to remember alias, Update-Dbachecks.

 

Read more

For more information about dbachecks, visit these links by dbachecks contributors!

- Chrissy

]]>
https://dbatools.io/installing-dbachecks/feed/ 14 7099
introducing dbachecks – a new module from the dbatools team! https://dbatools.io/introducing-dbachecks/ https://dbatools.io/introducing-dbachecks/#comments Thu, 22 Feb 2018 12:00:28 +0000 https://dbatools.io/?p=7140 In mid-December, we began working on a new PowerShell module for the SQL Server Community. This free and open-source project can be found in the SQL Server Community Collaborative’s repository. Contributions from the community are welcomed and encouraged 🤗

Intro

dbachecks is a framework created by and for SQL Server pros who need to validate their environments. Basically, we all share similar checklists and mostly just the server names and RPO/RTO/etc change.

This module allows us to crowdsource our checklists using Pester tests. Such checks include:

  • Backups are being performed
  • Identity columns are not about to max out
  • Servers have access to backup paths
  • Database integrity checks are being performed and corruption does not exist
  • Disk space is not about to run out
  • All enabled jobs have succeeded
  • Network latency does not exceed a specified threshold

We currently provide over 80 checks, as can be easily seen using Get-DbcCheck:

How to use

Usage can be approached in two ways:

Run directly from the command line

As simple as Invoke-DbcCheck -SqlInstance sqlprod01 -Checks SuspectPage, LastBackup

Schedule checks

Command line execution is good in a pinch, but ongoing checks are the ultimate goal. In order do this, you can do the following:

  • Set your desired configuration
    Configs can be set for specific environments like Production, Test or Development or for an application, like SharePoint or a custom-built app
  • Export your configuration
    Export your environment or application configuration so that it can be easily imported by your scheduled task
  • Schedule checks using Task Scheduler or SQL Server Agent
    I personally prefer Agent
  • Get notified via email or load up in Power BI

Check out our commands post page for more information.

Power BI is awesome

dbachecks also includes a built-in Power BI dashboard and it’s gorgeous 💅.

Whaaaaaat! Thanks to Cláudio Silva and Rob Sewell for that work of art. And thanks to Rob for making a sample dashboard available online.

Install

To learn more about prerequisites and installation, please visit installing dbachecks.

Development

Have questions about development? Please visit our creating tests for dbachecks.

Website

Unlike dbatools, there is no dedicated website for dbachecks at this time. The domain dbachecks.io does exist, however, and will be used for shortlinks <3.

License

dbachecks is MIT licensed

The MIT license is a short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

Learn more

This post just touched on an overview of the new dbachecks module. To learn more about dbachecks, check out these posts

If you have any questions, join us in #dbachecks on the SQL Server Community Slack.

Thanks for reading and we look forward to your feedback!
- Chrissy

]]>
https://dbatools.io/introducing-dbachecks/feed/ 9 7140
t-sql tuesday and new module teaser https://dbatools.io/new-module-coming-soon/ https://dbatools.io/new-module-coming-soon/#comments Tue, 09 Jan 2018 08:36:59 +0000 https://dbatools.io/?p=6904
TSQL2SDAY-150x150
 
Today’s blog post is part of T-SQL Tuesday. T-SQL Tuesday is the brainchild of Adam Machanic. It is a blog party on the second Tuesday of each month. Everyone is welcomed to participate.

This month’s T-SQL Tuesday, hosted by Arun Sirpal ([b]|[t]), is all about overcoming technical challenges.

The challenge

I always try to solve my technical issues with natively available (aka Microsoft) solutions. It’s one of the many reasons I love PowerShell.

When it comes to monitoring, I know there are some really wonderful solutions out there. SentryOne and SolarWinds come to mind but I don’t always need deep query level monitoring or I may not be able to pay licencing costs for all of my SQL Instances. But I do need to easily know if they are all set up correctly.

Ever since I was a baby DBA, I’ve wanted to create a centralized solution that I could roll in with and get going with after finding all of my servers. Over the years, I’ve tried to put together some ASP/VBScript solutions, then when I learned PowerShell, tried PowerShell and SQL Agent, but I just wasn’t feeling it. I could never figure out how to make the checks modular and universal. That is, until I learned about Pester in-depth from Rob Sewell.

The solution

The solution I’ve been looking for turns out to be a mix of dbatools and Pester. Pester is the first Open Source community project formally included in a Windows release! Windows 10 and Windows Server 2016 include Pester by default.

Pester makes it easy to standardize tests or “checks” because it can output its results in a number of standardized formats, including NunitXml and JSON. It’s all PowerShell, after all.

dbatools makes it easy to perform these checks without installing additional software or stored procedures on each of my servers. I have one central workstation that needs to be updated and checking hundreds of servers is as easy as checking just one.

So after poring over Rob’s prodigious GitHub Presentation Repository, I found a bunch of his tests, and added them to a newly created module. I then created an index of the checks to make them easy to access. Once I got the proof of concept down, I invited a few people from the community who I know are involved in Pester and asked them to help.

The result has been a dream come true!

Index

Index of checks. You can run them all, run by group or only run the specific tests that matter to your environment.

 

Power BI Universal Dashboard

Courtesy of Cláudio Silva. Just hit refresh and you’re all set!

 

Included Parser & Mailer

Also from Rob’s repo!

We are still working on the checks, but these screenshots should give you an idea about the new SQL PowerShell module that Rob and I will be premiering at our SQLBits PowerShell Precon, Reliable, Repeatable, & Automated: PowerShell for DBAs, in London on Thursday, February 22 2018.

Interested in finding out more? Find us at SQLBits!

]]>
https://dbatools.io/new-module-coming-soon/feed/ 10 6904