Thursday, May 26, 2016

PowerShell v3 in a Year Day 2 A Through Z

,
Following on the heels of my post earlier today, "PowerShell (v3) in a Year - Day 2: ?", I wanted to work through the next topic, A:. Now, A: is really just an alias for the cmdlet Set-Location. And, to save myself about 25 more related threads, for B: , C: , D:, etc, I decided to cut to the chase. These aliases are just quick keys to allow navigation top from one location too another. If, for example, I want to just jump to another drive, I can call B:, C: and so forth, and, thanks to aliasing, PowerShell connects the Set-Location cmdlet with these two key combos under the hood. Although I dont intend to get into the help for Set-Location today, I think a quick glance at the help will give some context to current discussion.

According to get help,
The Set-Location cmdlet sets the working location to a specified location. That location could be a directory, a sub-directory, a registry location, or any provider path.
If you look up the get-help for cd, it to is an alias for Set-Location. For anyone familiar with cmd.exes syntax, cd stands for c[hange] d[irectory]. Putting these commands together, it is pretty clear, A:, B:, C:, and the like, are just quick ways to get from one location to another. The nice thing about this set of 26 aliases is their succinct nature. Two characters, and, a stroke of the [Enter] key, and, voila, youre a the root of a new directory.

Unlike cmd.exe, however, these aliased commands are helpful in PowerShell because they tap into much more than your traditional file system. As with most things PowerShell related, the use of Set-Location works with a variety of providers. So, while there are built-in, that is to say, Microsoft-provided, aliases of the two character sort, you can add many more on your own. Just looking at the four examples from Get-Help -Examples, there are some pretty cool things to think about:
  • set-location HKLM:
  • set-location env: -passthru
  • set-location C:
  • set-location -stackName WSManPaths
Each of these tap into a different provider. The one that I think is the coolest is the -StackName, but, thats just me. Conceptually speaking, there really isnt a lot to wrap your head around with these aliases. 

One thing to keep your eye out for is the parameter sets. In v3, there are 3:
  1. Set-Location [-LiteralPath] [-PassThru] [-UseTransaction []
  2. Set-Location [[-Path] ] [-PassThru] [-UseTransaction] []
  3. Set-Location[-PassThru] [-StackName] [-UseTransaction] []
When working with these various parameter sets, just pay attention to which options you have. In most cases, the options, C:, D:, E, F: and maybe a few others, are about all youll need on a daily basis.  One concept I look forward to dealing with as I revisit the about_* topics, is the use of transactions with Set-Location. Though there is no clear application for transactions at this point, if there is anything I have learned working with PowerShell, it is always a good idea to check something out when it comes up. More than likely, you will be facing that concept again, and, many times, it is sooner rather than later. Hopefully, Ill get my head around transactions here shortly.

Getting much further into the underlying, and, related cmdlets would prolong what really is a simple cmdlet/alias pairing. If you still have trouble figuring out how to use these, look at some of the examples with Get-Help -Examples and play with them. If it still doesnt click, post or contact me. With that, I am signing off until tomorrow, when I will tackle the about_aliases. That ought to flow nicely from this post.

0 comments to “PowerShell v3 in a Year Day 2 A Through Z”

Post a Comment

 

Computer Info Copyright © 2016 -- Powered by Blogger