Stairway to SQL PowerShell Level 1: SQL PowerShell Basics

  • That worked.


  • Good start, thanks for sharing!

    Wait for more to come...

  • "We will create a prompt function that will change the behavior of your environment, more specifically the prompt you see in the console. This is precisely the reason for a profile"

    I am using Powershell 2.0 and Win7. I can see my console prompt in ps c:\usersame format (even then, when i am not running my console as an administrator ). Could some one help me understanding profiles? Is it mandatory to do profiles to change the console prompt? (i tried logging on to different users accounts and its same for all) or am i missing something?

    Thanks for your help!

  • Well, to change the prompt, there just needs to be a prompt function in place. It does not have to be in a profile, but it is convenient to have it there.

    The Prompt function is literally this:

    function Prompt {

    return "New Prompt:"


    If you type this into the command window like this:

    function Prompt { return "New Prompt: " }

    Your prompt will immediately change in your window. So the key to the profile is that if you put it in your profile, the prompt will be changed at the time of PowerShell startup.

    The trick now is to learn the options you have to get at information to change either just the prompt or the title bar of the window, etc.

    Does that help?

    Ben Miller
    Microsoft Certified Master: SQL Server, SQL MVP
    @DBAduck -

  • Yes, got it! Thanks a lot Miller 🙂

  • I found

    $wintitle = $CurrentUser.Name + " " + $Host.Name + " " + $Host.Version

    was sufficient to get the version to display the way I expected.

  • I know I'm late for the party and dumb as a piece of plastic, but there is no "documents" or "windowspowershell" anywhere under my profile. when I type $profile in Powershell I get this:

    PS C:\Users\whouston.SFI> $profile


    PS C:\Users\whouston.SFI>

    If I understand correctly, I'm to save the notepad file in the same folder as my profile, right? I can't see these folders. I'm an admin on the machine and have unchecked all the boxes under folder and search options which hide system folders, etc. ( I do this for every machine I work on). what am I not understanding?

    Thanx for the series! I'm GOING to learn powershell, so this is a big help!

    Wallace Houston
    Sunnyland Farms, Inc.

    "We must endeavor to persevere."

  • If I understand correctly,

    I expect you have a folder on your machine at 'C:\Users\whouston.SFI\Documents', unless the way you set up your machine is radically different than most machines I've met. If you don't have a WindowPowerShell folder below that, make one. In that folder, create a text file named Microsoft.PowerShell_profile.ps1. In that file, write the PowerShell that you want to run when your console starts. It ought to be just that easy.

  • Naaa. No "documents" folder. Do have "My Documents". I will build BOTH folders and proceed as you suggested. I didn't intentionally change anything about the PC setup, but I've had stranger things happen.


    Wallace Houston
    Sunnyland Farms, Inc.

    "We must endeavor to persevere."

  • Great post. One thing I would comment on is the powershell versions that you are talking about. Powershell V5 is now available as a preview, and for Enterprise management, workflows that were introduced in V3.0 and DSC in V4 add massive benefits. Will you be covering those as well?



  • This looks excellent.

    I had a problem with the notepad $profile command. It would not open Notepad.

    To check I entered the following commands:

    Test-Path $profile - it returned False

    I entered the following command:

    New-Item -path $profile -type file -force

    notepad $profile now launches Notepad

  • There may be a revision of the earlier articles. I wrote them when the versions were not as advanced as today.

    We will see when I finish the last few articles and then go revise.

    Ben Miller
    Microsoft Certified Master: SQL Server, SQL MVP
    @DBAduck -

  • Yes, in most cases you can use notepad $profile and it will open up profile and let you say "Yes" create a new file, but only if there is a folder WindowsPowerShell in your Documents directory.

    The other way to do it is how you did with New-Item. When I go back and revise the articles, I will add that item.


    Ben Miller
    Microsoft Certified Master: SQL Server, SQL MVP
    @DBAduck -

  • $wintitle = $CurrentUser.Name + " " + $Host.Name + " " + $Host.Version

  • $wintitle = $CurrentUser.Name + " " + $Host.Name + " " + $Host.Version

Viewing 15 posts - 16 through 30 (of 36 total)

You must be logged in to reply to this topic. Login to reply