:::: MENU ::::
Browsing posts in: Windows

Find certificates based on Thumbprint

If you see warnings in the error log about certificates about to or have expired you can search for them via Thumbprint using Powershell, eg Thumbprint is 80d831e902ecd3e2e44c0426b2cea804b57d40fc, search for them with:

Get-ChildItem -Path cert: -Recurse | where {$_.Thumbprint -eq “80d831e902ecd3e2e44c0426b2cea804b57d40fc”} | Format-List -Property *

Remote Desktop Settings

Super useful setting to be able to resize the rdp window having the contents to resize with it. Just open your rdp file and add:
smart sizing:i:1

Save and connect and tada, you can resize the window.

Look here for a lot of other configuration parameters.



Needed to copy all contents from one disk to another, with all permissions and everything, including subcatalogs whether empty or not.

This seems to work, I am copying from W: to U: with a verbose log on C:, You may want to omit the verbose part, the /V, as it generates a LOT of log.

robocopy W: U: /COPYALL /E /Z /V /LOG:C:\temp\Robocopy_log_W_to_U.txt /R:5 /W:5

It will retry 5 times if a file is locked and wait 5 seconds between each try, the defaults are ridiculously high so they need to be set lower.

Overwrite is set as default, but if the source and target have the same timestamp and size it will skip that file.

Be careful not to set /E and /S as /S will take precedent over /E so no empty catalogs will be copied. Weird…….

That’s all for me. See more at http://ss64.com/nt/robocopy.html


Failover Windows Cluster group

Trying to failover the Quorum disk on a Windows 2012 Cluster via GUI is a no go, instead use Powershell.
Assuming your Cluster Group is called “Cluster Group”.


to list all your groups.

Failover with:

move-ClusterGroup  -Name "Cluster Group"

Powershell copy database backups

Needed to setup an automatic copy of latest SQL Server database backup from production database to test server. A twist was that the production database was setup with AlwaysOn database mirroring with backups taken on the secondary replica. So, how do we find the latest database backup? I solved it by querying both msdb’s and comparing the backup dates. Ugly but it works…

# Script to setup automatic copy of database backup from AlwaysOn
# production servers to test server
# I use it on a separate admin server
# Run this script as a Scheduled Task or on demand,
# the user need to be able to access the backup files remotely
# and also on the destination server catalog
# This is just an example script, needs to be edited to suit your environment
# It works by logging in to both AlwaysOn instances and
# checking the file path and time stamp
# for the latest backup of the database you want to copy.
# You need a simple user to log in to the production instances,
# no special rights granted,
# public can read this information in msdb, I use the login RemoteFilecopy
# I use diskshares for backups in the form of \\servername\drive$
# eg. \\\z$
# edit to suit your need

########## Common variables for all copying ##########

$db = "msdb"


$ServerInstance1 = "PRODUCTION_SERVER_1"
$ServerInstance2 = "PRODUCTION_SERVER_2"
$SourceDatabase = "DATABASE_NAME"

# Check latest backup from each server and get the latest one
$sqlstring = @"
SELECT TOP 1 bmf.physical_device_name [Filename], bs.backup_finish_date [BackupDate]
FROM msdb.dbo.backupmediafamily bmf
INNER JOIN msdb.dbo.backupset bs ON bmf.media_set_id = bs.media_set_id
WHERE bs.type = 'D'
AND bs.database_name = '$SourceDatabase'
ORDER BY bs.backup_finish_date DESC

# I use a simple dummy date below just to have a non-null date to compare to
# If your backups are older than 2010, than you have other problems :-)

$Filename1 = (Invoke-Sqlcmd -Username $user -Password $password -Serverinstance $ServerInstance1 -Database $db -Query $sqlstring).Filename
$BackupDate1 = Get-Date "1/1/2010"
if($Filename1.length -gt 0 ) {
$BackupDate1 = (Invoke-Sqlcmd -Username $user -Password $password -Serverinstance $ServerInstance1 -Database $db -Query $sqlstring).BackupDate

$Filename2 = (Invoke-Sqlcmd -Username $user -Password $password -Serverinstance $ServerInstance2 -Database $db -Query $sqlstring).Filename
$BackupDate2 = Get-Date "1/1/2010"
if($Filename2.length -gt 0 ) {
$BackupDate2 = (Invoke-Sqlcmd -Username $user -Password $password -Serverinstance $ServerInstance2 -Database $db -Query $sqlstring).BackupDate

if ( $BackupDate1 -gt $BackupDate2 ) {
$SourceBaseCatalog = "\\PRODUCTION_SERVER_1\DISKSHARE$\"
$Filename = $SourceBaseCatalog + $Filename1.Remove(0,3)
if ( $BackupDate1 -lt $BackupDate2 ) {
$SourceBaseCatalog = "\\PRODUCTION_SERVER_2\DISKSHARE$\"
$Filename = $SourceBaseCatalog + $Filename2.Remove(0,3)
if ( $BackupDate1 -eq $BackupDate2 ) { Write-Host "Found no backup or same date, break!!"; Break; }

################### START COPYING BACKUP ################################

# Change from sqlps to normal filesystem usage
Set-Location C:

# Create destination filename, I use the original name plus "FULL_LATEST"
$DestinationFilename = "$DestinationCatalog" + $SourceDatabase + "_FULL_LATEST.bak"

# Check if file exists, exit otherwise
IF(!(Test-Path -path $Filename))a
{Write-Host "$Filename not found!"; exit}

# Check if destination catalogexists, exit otherwise
IF(!(Test-Path -path $DestinationCatalog)) {
Write-Host "$DestinationCatalog not found, exiting`r`n"

# Copy file from PROD server to TEST server
Write-Host "Start copying file $Filename to $DestinationFilename"

# Uncomment line below to actually copy the file, but ONLY after testing, there are numerous possibilities to screw up here :-)
# Copy-Item -Path $Filename -Destination $DestinationFilename
########## COPY BACKUP DONE ##########

Windows Junctions

In Unix and Linux creating links is something you do all the time, maybe you have a version number in that new apache catalog but you want to continue to just use \opt\apache or something, in Windows it’s not used much, well at least not according to my experience.

The other day I was upgrading SQL Server, the original media was on a catalog on C: (c:\nt) but there was not enough space on C: to hold both the original media and the new, what to do?

I moved the original media to my shiny large X: disk but the setup program was looking for the original on C:\NT, again what to do….?

You create a junction on C:\NT that points to X:, the program will not notice it, it thinks the media is still on C:\NT


Start CMD with admin rights.

C:\>cd nt

C:\NT>mklink /J c:\NT\Server_Developer_Edtn_2012_X64_SP1 x:\Server_Developer_Edtn_2012_X64_SP1

Junction created for c:\NT\Server_Developer_Edtn_2012_X64_SP1 <<===>> x:\Server_Developer_Edtn_2012_X64_SP1

 Now you have a link c:\NT\Server_Developer_Edtn_2012_X64_SP1 that points to x:\Server_Developer_Edtn_2012_X64_SP1


Search for string in text files

So, in Windows we are missing the excellent *nix commands grep, awk and sed, what to do if you want to search for strings in a lot of textfiles, as logs.

I was interrested in how many times the string ‘UPDATE STATISTICS’ was written into log files, there were some 20 odd files, all of them more than 20MB in size. The logs were from a script running to update statistics in a lot of databases in one instance, Ola Hallengrens script, the files had the form:



So, it was actually quite easy, I opened cmd, cd to the log directory and ran:

for %f in (MP_UpdateStatistics_UserDB*) do find /c "UPDATE STATISTICS" %f


The string count is shown to the far right:

find /c "UPDATE STATISTICS" MP_UpdateStatistics_UserDB_20130808_230000.txt
---------- MP_UPDATESTATISTICS_USERDB_20130808_230000.TXT: 48303



AD Management on Windows 2008[R2], dsa.msc



Sometimes you need to check a users roles, permissions, members or something in the AD, I always forget how to install msa.dsc in Windows 2008[R2]:

Windows 2008

  • Open Server Manager, go to the Features section
  • Add Features
  • Remote Server Administration Tools – Role Administration Tools – Active Directory Domain Services Tools – Active Directory Domain Controller Tools
  • Next, Finish, etc


Windows 2008 R2

Start Server Manager (ServerManager.msc)
At Features -> add feature


  • Remote Server Administration Tools
  • Role Administration Tools
  • AD DS and AD LDS Tool
  • AD DFS Tools
  • AD DS Snap-Ins and Command-Line Tools


Done, no reboot needed.

Short cut with run as in windows

Windows allows you to run an application as another user then the one you are logged on as, normally done by right-clicking an application and choosing ‘Run as’.

But, what if you have an application you start and shutdown often, will get pretty tedious always filling in the user you want to run it as, better to change the short-cut to automatically do the run-as for you.

So, either create a new short-cut or open the properties of an already existing one.

In the ‘Target’ put something like this, substituting the domain\accountname for the one you want to run it as:

C:\WINDOWS\system32\runas.exe /user:domain\accountname c:\windows\system32\notepad.exe

And ofcourse change the path to the application, the path above is to notepad.

Now when you run the shortcut it’ll throw up a command window asking you for the password, type it, press enter and you’re done :-)

Check Windows uptime, latest reboot/restart and other stuff

I miss the *nix command uptime, so easy to use, Windows have a couple of ways to see uptime:

1. On Vista and 2008 the Task Manager has some added info, among them are ‘Uptime’, found in the Performance tab.

2. Open a cmd window, type


or for less information, pipe it to a find command eg.

 systeminfo | find "System"

3. Run a net command:

net statistics workstation