• Top Hey, Scripting Guy! Blog Posts for 2014

    Summary: Windows PowerShell MVP, Teresa Wilson, talks about the top Hey, Scripting Guy! Blog posts for 2014.

    Microsoft Scripting Guy, Ed Wilson, is here. Today we feature Honorary Scripting Guy and Windows PowerShell MVP, Teresa Wilson, aka The Scripting Wife.

    Hello everyone,

    I did a little research and came up with the top five Hey, Scripting Guy! Blog posts for 2014 (based on number of views). The results are sort of interesting. The top post is a basic article dealing with files and folders. The second most popular post talks about network adapters. The third is another basic article about looping, and the last two articles are about special purposes.

    So what does the list tell us? Who knows—other than that there are all sorts of people who are using Windows PowerShell and who read the Hey, Scripting Guy! Blog. Maybe that is the point.

    Anyway, here are the top five posts for 2014:

    1. List Files in Folders and Subfolders with PowerShell
    2. Enabling and Disabling Network Adapters with PowerShell
    3. Basics of PowerShell Looping: Foreach
    4. Use PowerShell to Manage Office 365 Users
    5. Use PowerShell to Create CSV File to Open in Excel

    Wishing you a wonderful New Year.

    ~Teresa

    I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

    Ed Wilson, Microsoft Scripting Guy 

  • PowerTip: Find PowerShell User Groups

    Summary: Learn how to easily find Windows PowerShell user groups.

    Hey, Scripting Guy! Question Where can I find information about which cities have Windows PowerShell user groups?

    Hey, Scripting Guy! Answer There are two locations:

    Also feel free to contact me directly at ScriptingWife@hotmail.com. Sometimes I know of cities with people who would like to meet-up for an informal chat about Windows PowerShell.

    Note  This tip was supplied by Windows PowerShell MVP, Teresa Wilson.

  • Top PowerShell Scripts of 2014

    Summary: Windows PowerShell MVP, Teresa Wilson, talks about the top Windows PowerShell scripts of 2014 in the Script Center Script Repository.

    Microsoft Scripting Guy, Ed Wilson, is here. Windows PowerShell MVP, Teresa Wilson, also known as "The Scripting Wife" is here today to tell us the five most popular scripts that were downloaded from the Script Center Repository in 2014. Take it away Teresa...

    Hello all. I have gathered some stats for you. Here are the top five most popular scripts that were downloaded from the Script Center Repository in 2014:

    1. File System Security PowerShell Module 3.2.2 by Raimund Andree

    This script enables much easier management of permissions on files and folders by using Windows PowerShell. It was originally released in 2011 and it was updated in 2014.

    2. Windows Update PowerShell Module  by MichalGajda

    This function is a piece of the PSWindowsUpdate module for managing Windows Update on a computer system running Windows. The whole module contains a set of functions to check, download, and install updates from Windows PowerShell. It was originally released in 2011 and it was updated in 2014.

    3. PowerShell: Create Active Directory Users Based on Excel  with input by HicanNL

    This script creates users in Active Directory based on the settings in the input file. (It includes an Excel/CSV file as an example of the input file.) It was originally released in 2012 and it was updated in 2014.

    4. Remove Windows Store apps in Windows 8 by the OneScript team

    This script can be used to remove multiple Windows Store apps from a user account in Windows 8. It provides a list of installed Windows Store apps. You can specify the application IDs, and remove them all at one time. It was originally released in 2011 and it was updated in 2014.

    5. Download and Install SharePoint 2013 Prerequisites on Windows Server 2012 by Craig Lussier

    These Windows PowerShell scripts automate downloading and installing the SharePoint 2013 prerequisites on computers running Windows Server 2012. The scripts assist people who need to install SharePoint 2013 offline or want to manually install its prerequisites on computers running Windows Server 2012. This was originally released in 2012 and it was updated in 2014

    As you can see, all the previous scripts were originally released in an earlier year and updated in 2014. I looked for the top two scripts that were released in 2014, and I came up with the following:

    1. DSC Resource Kit (All Modules) by the Windows PowerShell team

    The DSC Resource Kit is a collection of experimental Desired State Configuration (DSC) resources that were released by the Windows PowerShell team, designed to help you get started with DSC. These resources allow you to configure Active Directory, SQL Server, IIS, Hyper-V, RDSH, and more.

    2. CleanMgr.exe/KB2852386 Automation Example by Tom Moser

    This script is an automation example for KB2852386. (KB2852386 is an update for the Disk Cleanup wizard.)

    I hope you have had a wonderful 2014 and are looking forward to the great things you can accomplish with Windows PowerShell in 2015.

    ~Teresa

    Thank you, Teresa, for putting this list together for us.

    I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

    Ed Wilson, Microsoft Scripting Guy 

  • Weekend Scripter: Playing with PowerShell Prompt

    Summary: Microsoft Scripting Guy, Ed Wilson, talks about playing with the Windows PowerShell prompt.

    Microsoft Scripting Guy, Ed Wilson, is here. It is time to round up all of those end-of-the-year kinds of things. This is, in fact, the last weekend Hey, Scripting Guy! Blog post of 2014. Not sure what that means; but it is true, this is the last weekend post of the year. Not that I am going to do anything special, or make a big deal of it, but I just was thinking about it.

    One thing I like to do from time-to-time, is override my Windows PowerShell prompt. The cool thing is that I can do it on the fly. This is because it is simply a function—and like all functions, I can overwrite the behavior.

    Like all other Windows PowerShell functions, the Windows PowerShell prompt resides on the Function drive. I can use the Get-Content cmdlet to retrieve the current value. Here is the one on my computer:

    PS C:\Users\ed> Get-Content Function:\prompt

    "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

    # .Link

    # http://go.microsoft.com/fwlink/?LinkID=225750

    # .ExternalHelp System.Management.Automation.dll-help.xml

    OK, it is a little shaggy. The main thing, in fact, the only executing code is a one-liner. It retrieves the current location, and it displays a right arrow if I am in a nested prompt. It is basic and generally does what I want. It also lets me have pretty much all the space at the Windows PowerShell console that I could possibly want.

    But, it can be shorter. In fact, I know quite a few people who omit the initial PS. Here is a prompt that does that:

    Function prompt {"$($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "}

    All I need to do is to type the command at the Windows PowerShell console, and press ENTER. Here is the command and its results:

    Image of command output

    When I close and re-open the Windows PowerShell console, my Windows PowerShell console prompt returns to the default value.

    But suppose that I do not care what my current location is. In that case, I can retrieve a few more spaces on the Windows PowerShell console line. Here is an example of that:

    Function prompt {"$('>' * ($nestedPromptLevel + 1)) "}

    The prompt is shown here:

    Image of command output

    In each case, I use the content of the previous function to create my new prompt function. But I do not need to do that. I can, for example, create a prompt that is totally mine. Here is an example that displays the current date:

    Function prompt {"HSG $([datetime]::Now.ToShortDateString()): "}

    Here is the prompt:

    Image of command output

    One thing that might be fun to do is change the background color of the Windows PowerShell console—on a random basis. Here is a prompt that does that:

    Function prompt {[console]::backgroundcolor = $(Get-Random -Minimum 0 -Maximum 15); "HSG $([datetime]::Now.ToShortDateString()): "}

    Keep in mind that not all colors of a background color will be compatible with the foreground color, so you might want to add a bit of logic if you really want random colors. Each time a Windows PowerShell command runs, the background color changes, but the foreground color is currently remaining the same. Here is what that might look like:

    Image of command output

    Remember that if things don’t work out, all you need to do is close Windows PowerShell and re-open it. This is because you are creating a temporary function that is only stored in memory. I can redefine it at will and on-the-fly. If I come up with something I really like, I can add it to my Windows PowerShell profile. I will talk about that later.

    For now, have fun, and let me know what crazy ideas you come up with.

    I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

    Ed Wilson, Microsoft Scripting Guy