New SQLServer DSC Resource cSQLServer

Today we have released a new SQL Server DSC Resource that has been created by merging the already existing xSQLServer and xSqlPs resources and adding new functionality like:

– SQL Always-On (with domain credentials)
– SQL Always-On between 2 Clusters
– SQL File streaming
– SQL Always-On with Listener

For more information please check the source at:

Demo Video:

A more in depth article will be published early January!


Activate Windows VMs using Powershell Direct

# This code requires Windows 10 professional/Enterprise or Windows Server 2016
$vmname = read-host "VMName"
$key = read-host "Windows Key"
Invoke-Command -VMName $vmname -ScriptBlock {
Write-Verbose -Message "Attempting to inject Windows key: $key"
Cscript.exe $env:SystemRoot\System32\slmgr.vbs -ipk $key
Write-Verbose -Message "Attempting to activate Windows key"
Cscript.exe $env:SystemRoot\System32\slmgr.vbs -ato
} -ArgumentList $key


Using Powershell to get your server’s uptime!

I have always missed the option in windows to just easily see the uptime from a server.

Ofcourse we have the uptime.exe available from Microsoft, but I wanted to have something available directly from powershell.

For starters we could get the last bootuptime from WMI with the following query

(Get-WmiObject -Class win32_operatingsystem).lastbootuptime

Since this is not really in a nice format, lets change it into something we can read

[System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject -Class win32_operatingsystem).lastbootuptime)
Tuesday, October 6, 2015 10:37:14 AM

Now that we have the bootup time/date in a readable format we can substract this date from our current time/date to get our actual uptime.

((Get-Date)-([System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject -Class win32_operatingsystem).lastbootuptime)))

Days              : 0
Hours             : 0
Minutes           : 16
Seconds           : 8
Milliseconds      : 736
Ticks             : 9687365862
TotalDays         : 0.0112122290069444
TotalHours        : 0.269093496166667
TotalMinutes      : 16.14560977
TotalSeconds      : 968.7365862
TotalMilliseconds : 968736.5862

And there you go, you can now see the uptime for your server. I took this along a bit and created a powershell function to make it more usable for everyone in the company.

Function Get-Uptime 
            Get uptime for Server(s)
            This script will provide you the uptime for your servers in easy format
            .PARAMETER Servers
            One or multiple servers
            Get-Uptime -Server "computername"
            Request the uptime for a server
    [CmdletBinding(SupportsShouldProcess = $true)]

        [parameter(Mandatory = $true, HelpMessage = 'Please enter a computername.')]

    ForEach ($server in $servers) 
        Write-Verbose -Message "Retrieving information from $server"
        $uptime = ((Get-Date )-([System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject -Class win32_operatingsystem -ComputerName $server -ErrorAction SilentlyContinue ).lastbootuptime)))
        $server | Select-Object -Property @{
            Name       = 'Computername'
            Expression = {
            Name       = 'Days'
            Expression = {
            Name       = 'Hours'
            Expression = {
            Name       = 'Minutes'
            Expression = {
            Name       = 'Seconds'
            Expression = {
            Name       = 'Milliseconds'
            Expression = {

Now you only need to type Get-Uptime “servername” to get the uptime for the server you wish 🙂

PS C:\> get-uptime localhost | FT

Computername Days Hours Minutes Seconds Milliseconds
------------ ---- ----- ------- ------- ------------
localhost       0    19      49      32          478


Zipping your DSC Resources

When you are setting up a DSC Pull scenario, you will have to zip your DSC Resources in a correct format and by using proper tooling.

At first you need to zip your primary directory, and you have to give your zip file the correct naming. This should be (see screenshot below), and then placed in the “C:\Program Files\WindowsPowerShell\DscService\Modules directory”.PSDSC_Pull_Server

Please be aware that even though its ‘just a zip file’ not all programs zip the same way, if you for example use 7zip or winrar you could bump into eventid 4104: Failed to extract the module from zipfile.                                            PSDSC_notpropperlyzipped

If you however use the windows native compressing engine, everything will work out fine.PSDSC_zippedok

DSC Resource versioning fixed with WMF5 Production preview!

Last week I blogged about an issue with the DSC resource folder versioning in a DSC Pull scenario. DSC Resource folder versioning issue in a DSC-Pull scenario.

This week Microsoft released a new version of WMF 5.0  which fixes a whole range of issues.

While you still have to zip your DSC Resource without the version folder, the DSC engine now extracts the ZIP file to the corresponding folder version!

DSC Resource zip structure:


DSC Resource client structure:


This means that now, we can use multiple versions of a DSC Resource on the same client. This will help when for example you only want to update 1 partial configuration on a server that uses a newer resource, while not having to update dependent others.

DSC Resource folder versioning issue in a DSC-Pull scenario.

Please be aware of the following if you are using DSC Pull with folder versioning in your DSC Resources

In my case, I have a custom DSC Resource named cDNSRecord with the following directory structure: .\cDnsServer\\DSCResources\cDNSRecord.

It seems that currently as in WMF 5.0 (April 2015 Preview) it is not supported to have resources with folder versioning in a DSC Pull scenario and will most likely end you up with error 4104 in the event log:

ErrorId is 0x1. ErrorDetail is The PowerShell DSC resource % not contain the corresponding MOF file %.


A Work-around to this solution is simple:unzip your resource, and remove the folder versioning to for example: .\cDnsServer\DSCResources\cDNSRecord

While you can now use your DSC Resource in a Pull scenario, this does mean that you cannot use multiple versions of a DSC Resource on 1 sever if you use DSC Pull. This also means that if you want to upgrade to a newer version for this DSC Resource you will first need to remove the old version from the C:\Program Files\WindowsPowerShell\Modules directory on this specific server.

If you forget to remove the old folder you will most end up with another errorid 4252 in the event log:

Error Message: Installation of module % failed since the module directory already exists at %.Message ID: ModuleDirectoryAlreadyExistsEventID4252-2DSC

This can be resolved by using the AllowModuleOverwrite = $true value in your LCM configuration.

Hopefully this issue will be resolved in a future release of WMF5.


Scan Cluster Volume Health

I created this function some time ago already when we did not have the SCOM Management Pack for Windows Clusters imported yet.

This script basically scans a Cluster, to scan its current CSV State, and report you the current size/usage/freespace available.

The output of this script can be used to filter out unhealthy volumes, or volumes that are filling up!

Function GetClusterVolumeState{
Retrieve information about the Cluster Volume Health
The GetClusterVolumeState function retrieves information about the cluster volumes on a certain cluster.
This information will show the Cluster, Volume, Health and Disk space.
One or multiple clusters you would like to retrieve information from
Retrieve information about the Clustervolumes for Cluster01
RI-GetClusterVolumeState -clusters "Cluster01"
This script was written by Danny den Braver @2013, for questions please contact

foreach ($Cluster in $Clusters){
    # Test Connection availability and continue if $true
    $testconnection = Test-Connection $Cluster -Quiet
    if ($testconnection -eq $true){
        Write-Verbose -Message "Scanning: $Cluster for clusterdisk information"
	    # Get CSV Volumes
	    $CSVDisks = Get-ClusterSharedVolume -Cluster $Cluster
	    foreach ($CSVDisk in $CSVDisks){
		    # Get CSV VolumeInformation
		    $CSVVolumeInfo = $CSVDisk | Select -Expand SharedVolumeInfo
		    $CSVFriendlyName = $CSVVolumeInfo.FriendlyVolumeName
		    $CSVVolume = ($CSVFriendlyName.Split("\")[2]).ToLower()
		    $CSVState = $CSVDisk.State
		    # Get CSV free space
		    [int]$CSVDiskDriveFreeSpace = ([math]::round((($CSVVolumeInfo | Select -Expand Partition).FreeSpace / 1GB), 0))
		    # Get CSV total space
		    [int]$CSVDiskSpace = ([math]::round((($CSVVolumeInfo | Select -Expand Partition).Size / 1GB), 0))
		    # Get CSV used Space
		    [int]$CSVDiskDriveUsedSpace = [int]$CSVDiskSpace - [int]$CSVDiskDriveFreeSpace
		    # Get CSV Health
		    if ($CSVState -eq "Online"){
			    if ($CSVVolumeInfo.MaintenanceMode -eq $False){
				    if ($CSVVolumeInfo.RedirectedAccess -eq $True){
					    $CSVHealth = "Warning"
					    $CSVHealthDetails = 'Volume is in redirected mode.'
				    else {
					    $CSVHealth = "Healthy"
					    $CSVHealthDetails = 'Volume is healthy.'
			    else {
				    $CSVHealth = "Maintenance"
				    $CSVHealthDetails = 'Volume is in maintenance mode."'	
		    else {
			    $CSVHealth = "Critical"
			    $CSVHealthDetails = 'Volume is in offline state.'
		    # CSV Output
            $clustername = $cluster -replace "",""
            $clustername | select   @{l="Clustername";e={$Clustername}},
                                    @{l="Volume"; e={"$CSVVolume"}},
                                    @{l="DiskSpaceGB"; e={"$CSVDiskSpace"}},
                                    @{l="UsedSpaceGB"; e={"$CSVDiskDriveUsedSpace"}},
                                    @{l="FreeSpaceGB"; e={"$CSVDiskDriveFreeSpace"}},
                                    @{l="Health"; e={"$CSVHealth"}},
                                    @{l="Health Description"; e={"$CSVHealthDetails"}}
    else { Write-Warning "Could not connect to $Cluster" }


Make a SSH Connection using Powershell

Ever needed to connect to a hardware or unix interface from a windows box? For example to manage HP Servers / Interfaces, or to run some code on a Linux appliance?

Over at they have an answer to this: SSH-Sessions powershell module.

Copy the SSH-Sessions folder to your C:\Windows\System32\WindowsPowerShell\v1.0\Modules directory and then unblock the SSH.Net library using Unblock-File C:\Windows\System32\WindowsPowerShell\v1.0\Modules\SSH-Sessions\Renci.SshNet.dll

After that you can just Import-module the SSH-Sessions and you’re on your way:

get-help *ssh*

Name                    Category  Synopsis
----                    --------  --------
Get-SshSession          Function  Shows all, or the specified, SSH sessions in the global $SshSessions var...
Remove-SshSession       Function  Removes opened SSH connections. Use the parameter -RemoveAll to remove a...
New-SshSession          Function  Creates SSH sessions to remote SSH-compatible hosts, such as Linux...
Invoke-SshCommand       Function  Invoke/run commands via SSH on target hosts to which you have already op...
Enter-SshSession        Function  Enter a primitive interactive SSH session against a target host....