PowerShell has become the ultimate choice for many database administrators because of its efficient way of handling and managing automation in a simple, quick way. It’s built on .NET Framework and uses Object Models such as COM, ADSI, ADO, and WMI. PowerShell has replaced the traditional way of scripting that used many legacy scripting practices to monitor SQL instances.
I’ve been asked on several occasions about how to store the output of PowerShell WMI data into the SQL table. The question comes up so frequently that I decided to write this article.
When sending data within a system (such as a PowerShell object to a cmdlet), the process is straightforward. However, with non-native data interchange (for instance, WMI to SQL), the process can potentially get complicated. Due to this, many purists suggest sticking to simple interchange formats, such as CSV, JSON or in some cases, XML.
Let’s get out and see the possible options to transform WMI data to SQL table. In this article, we will:
- discuss Invoke-Sqlcmd
- talk about the .NET class libraries
- talk about exporting data using various Export* cmdlets
- learn how to use Windows Management Instrumentation (WMI)
- discuss SQL Constructs to load data from file
- and more
This guide details the working example of checking disk space by querying WMI.
We discuss the transformation of the above data into a SQL Table using some direct as well as indirect methods in this post:
- using Invoke-Sqlcmd
- using ADO
- WMI Query
- using Export commands such as JSON,XML and CSV
PoSH->Data Transformation -> SQL Table