Code snippets : PowerShell : Changing script execution policy


Handy quick one to change script execution policy for PowerShell:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force

Now all scripts should work fine 🙂


How-To : Promote Windows Server 2012 Core to first Domain Controller in Forest


In order to create new Forest and promote Windows Server 2012 Core to be Domain Controller for that Forest, first Active Directory Services Role has to be added:

Install-WindowsFeature AD-Domain-Services –IncludeManagementTools

Once Active Directory DOmain Services role is installed we can promote server to be first Domain Controller in the Forest.

Install-ADDSForest -DomainName "lab.corp" -DomainNetbiosName "LAB" -DomainMode Win2008R2 -ForestMode Win2008R2 -InstallDns -Force

And after some time new Forest and Domain Controller is ready to use.


Code snippets : Downloading file from URL in PowerShell


To download file from URL I used following piece of code:

$fileURL = "http://server/file.zip"
$fileName = "C:\Downloads\file.zip"
$webclient = New-Object System.Net.WebClient

Code snippets : Unzip file in PowerShell


Recently I needed to unzip file from PowerShell script. Here is result what I did use to achieve that:

$archiveDir = "C:\Downloads"
$fileZip = $archiveDir + "\file.zip"
$shell=new-object -com shell.application
$zip = $shell.NameSpace($fileZip)
foreach ($item in $zip.items())

Tips & Tricks : Enabling Windows Hyper-V 2012 Remote Management


After installing Windows Hyper-V 2012 sometimes there might be some issues with remote management (even if enabled via sconfig).

In that case few firewall rules might have to be enabled on Hyper-V machine using PowerShell:



Tips & Tricks : SQL Server “Cannot connect to WMI provider”


Recently I had issue which occured without any particular reason on SQL Server 2012. All of the sudden I start getting error message:

Cannot connect to WMI provider. You do not have permission or the server is
Note that you can only manage SQL Server 2005 servers with SQL
Server Configuration Manager.
Invalid Namespace.

when tried to run SQL Server Configuration Tools.

What resolved situation is command:

mofcomp C:\Program Files\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof