PowerShell 3.0 ISE ponderings

I have played around some with PowerShell and written a few pretty cool scripts to make some administration tasks easier. All of this was done with PowerShell 2.0. I use PowerGui as my editor of choice currently. It provided Intellisense that was not available with PowerShell 2.0 or the ISE.

I attended PowerShell Saturday here in Charlotte, NC on 9/15/2012. Ed Wilson, the current Microsoft Scripting Guy, kicked off the day. And what a day it was. If you have any desire to learn PowerShell, check out his blog as well as the Hey Scripting Guy! articles he publishes daily.

Now all that being said, I have started looking into PowerShell 3.0 which released when Windows Server 2012 did. There is an ISE, Integrated Scripting Environment, that is a host application for Windows PowerShell. This also existed for version 2.0 but has many improvements with the 3.0 release. Version 3 includes Intellisense very similar to what is available in Visual Studio. The ISE incorporates a script window, console and a vertical Add-on Tools pane. You can customize this to include all 3 or any combination.

As PowerShell has evolved, it has become more powerful. For example, version 2 had approximately 200 cmdlets. If there was not an existing cmdlet to achieve what you wanted to do, you could write your own or locate one that someone else had written and shared. Now enter today and PowerShell 3. There are over 2200 cmdlets included with this new release.

When I started using PowerShell, I was happy that they included DOS commands for things like dir and cd. Little did I know, but these are actually aliases that were created within PowerShell to provide quick access to things like the Get-ChildItem command. As you can see, both commands, dir and Get-ChildItem, return the same data:

image

You can find an entire list of aliases by entering Get-Alias.

There are also some very nice help options within the ISE. There is a Command Add-on that allows you to select a given command and see what options and parameter are available, as well as the ones that are mandatory. If a field is required, it is denoted by an asterisks. I chose the Get-AdUser cmdlet. As you can see, the Filter: parameter is required. From this Add-On, you can choose to Run, Insert, or Copy the command with the specified parameters.

image

There is also a new cmdlet named Show-Command that will provide this input box for the requested command if you decide not to have the Command Add-in loaded. Both of these options provide a GUI interface to visually see the required arguments and available parameters for any given command. If you enter Show-Command –Name Get-AdUser in the console, a pop-up window is displayed that contains the same information and functionality provided by the Command Add-On for Get-AdUser.

Another cool feature of the script window within the ISE is the ability to override the PowerShell ExecutionPolicy on a machine. A script is simply a group of commands that are executed together. You can enter this group of commands into the script window and execute them as one. As long as you have not saved the script, this will work around the execution policy. As soon as you save the script, the ExecutionPolicy is enforced and your script may or may not run. To see what your ExecutionPolicy is set to, you can run the cmdlet, Get-ExecutionPolicy. This becomes important if you are trying to run scripts that were downloaded from the internet. If your execution policy is set to Restricted, you will not be able to run these. A way around this is to using the script editor in ISE. You can copy the commands from your downloaded script into a new script window and run it.

I hope that these tips help you. I will continue to provide useful information as I work more with this interface.

Terri is a Support Specialist at OrcsWeb, a hosted server company providing managed hosting solutions.

Powershell Saturday 002

I was lucky enough to get to attend the Powershell Saturday event on 9/15. It was at the Microsoft Office in Charlotte. Ed Wilson, Hey, ScriptingGuy, was awesome. I love listening to people that get the technology that they talk about. He was energetic and fun. This was a great introduction to advanced day of learning for everyone. I would recommend this to anyone interested in learning more.

Terri is a Support Specialist at OrcsWeb, a hosted server company providing managed hosting solutions.

Find files with PowerShell

I struggle every day with the Search capabilities of Windows 7. I know there is no way I am the only person that has this problem. Found this great way to do a search of a location (local or UNC share) using PowerShell. This command will search the provided location recursively for all files matching a given criteria will output the list to a text file. I was wanting a full list of all music files in my iTunes library and used this gather that list. I will then able to clean-up as needed and was pleasantly surprised by some of the music that I have that was ‘forgotten’.

Get-ChildItem “file_location” -Recurse -Include “*.mp*”,”*.m4*” | foreach-object {$_.Fullname} | Out-File c:music.txt –width 1024

Have fun with this one. I know it has made my life easier.

 

Current ventures

So, I decided to try to learn some new development stuff to balance out my skills. Thanks to someone I work with at OrcsWeb, I got a really good tutorial for MVC3. I have been patiently working my way through this beginner’s guide to understand the parts and how they all work together.  I am also trying to get better with PowerShell since it is a great way to automate administrative tasks.