0

Tips & Tricks : Missing SQL Server assmeblies in PowerShell

-

When you try to connect to SQL Server from PowerShell script and you get following message:


Unable to find type [Microsoft.SqlServer.Management.Smo.Server]

then you have to download and install following components:

  • Microsoft System CLR Types for SQL Server 2008 R2
  • Microsoft SQL Server 2008 R2 Shared Management Objects
  • Microsoft Windows PowerShell Extensions for SQL Server 2008 R2

From here.

0

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 🙂

3

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.

0

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
$webclient.DownloadFile($fileURL,$fileName)
0

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())
{
 $shell.NameSpace($archiveDir).CopyHere($item)
}