• Caruncles (6/5/2014)


    following the logic that "the only dumb question is the one which doesn't get asked"-- how do you start Powershell? from SSMS, cmd prompt?

    It can differ a bit based on Operating System where within the start menu you find "PowerShell" to open it. As well, in some instances you want to start PowerShell "as Administrator" to have an elevate privileges within the PowerShell prompt.

    Basic:

    To just open PowerShell prompt (powershell.exe):

    - Start Menu, just type "PowerShell" for Windows 7 and onwards (including Server 2008 and up), this brings up the list for the ISE and just prompt both (x86) and x64 if you are on 64-bit server.

    To open SQL Server PowerShell (sqlps.exe):

    - Start Menu, just type "sqlps.exe". You generally will not see to many folks use this method.

    - Within SSMS 2008 or higher, right-click a folder or container and click "Start PowerShell".

    Note that using sqlps.exe you are not in the full blown "Powershell" world, you enter into SQL Server's made up world so to speak. The basic to understand is that general PowerShell commands may not work as you thing they should. This is because of the provider you are in within that particular prompt.

    Open SQL Server PowerShell from PowerShell.exe:

    - This is the most common method found and a bit easier to work in.

    - Within PowerShell prompt for SQL Server 2008 - SQL Server 2008 R2 you type: Add-PSSnapin *SQL*

    - Within PowerShell prompt for SQL Server 2012 and up you type: Import-Module SQLPS

    If you are at the basics I would start by reading through this guide, even though it is version 1.0 it covers the basics of how PowerShell operators.

    Then I would highly suggest watching the beginner PowerShell videos from MidnightDBAs, how I got started in it all.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton