Mar 10, 2016
In PowerShell Profiles – Have it Your Way Part 1 I talked about the many PowerShell profile scripts available to you – right out of the box there are 4 for the PowerShell console, and 4 for the PowerShell ISE (none created by default) – but what sort of cmdlets can you put into them? Well, one common command often put into profile scripts is drive mappings, and here again PowerShell gives you a plethora of choice.
Most of us are familiar with the standard file system drive mapping commands (in the “good old days" we played around with the Net Use commands etc.), but PowerShell takes the ease of mapping concepts that we are familiar with in the file system, and that same hierarchical access methodology, but with PSProviders and PSDrives, expands that methodology to lots of other hierarchical systems. In addition, PowerShell also uses generic nouns such as Item and ItemProperty in many PSProvider cmdlets, where an Item in the file system may refer to a directory or a file, but in the registry PSProvider an Item may be a registry key or setting, and in the Certificate store PSProvider, an Item may refer to a folder or a certificate. This makes management and navigation much more intuitive.
PSProviders
A PSProvider is simply an adapter that makes an external data store resemble a disk drive in PowerShell. It presents data in a dynamic, hierarchical fashion - in the file system we have the concepts of drives, folders (or directories), sub-folders (or sub-directories) and files, and with PowerShell we can apply that same logic to other data sources.
Some PSProviders are available straight away, such as the File System and Registry PSProviders, and others become available when you load their corresponding modules e.g. when you import the Active Directory module you are also capable of navigating AD in the same way you navigate your way through the file system. You can use the Get-PSProvider cmdlet to see all the currently available PSProviders and their capabilities, and the help alias to find out more about each provider – e.g. Help FileSystem, or Help about_Providers.
Because each provider connects to a different underlying technology, different PSProviders also have different capabilities, and these are also shown in the Get-PSProvider cmdlet. For example, the Registry PSProvider supports the transaction capability (the –UseTransaction parameter). Some of the main capabilities are:
- Credentials – for PSProviders that can support alternative credentials
- Filter – for PSProviders that can support filtering
- ShouldProcess – for PSProviders that can support the –WhatIf and –Confirm parameters, and
- Transactions – for PSProviders that can support transacted operations.
PSDrives
On the other hand, a PSDrive is a connection to a data store that can be identified by a name. A name can be just a single letter such as the “C" drive in the FileSystem PSProvider, or HKLM representing a connection to the HKEY_LOCAL_MACHINE hive in the Registry PSProvider. Again you can type in Get-PSDrive to get a list of the currently defined PSDrives. Drive names do not include a colon, however if you want to refer to a drive as a path, you include the colon. For example, when you use the New-PSDrive cmdlet, you do not include the colon in the drive name, but if you type in cd Variable: that will change the PowerShell focus to the Variable drive data source, and typing cd C: will change you back to the C drive in the file system.
One last thing – be wary of alias’s in PowerShell, particularly when it comes to the file system. PowerShell is great in that it can run a great deal of PROGRAMS that we are used to running in a standard command prompt – commands such as IPCONFIG etc. But keep in mind that a lot of the COMMANDS native to command prompt or the Linux shell commands etc. are actually aliases in PowerShell. This means that the command DIR (or even LS) is actually an alias in PowerShell for Get-ChildItem. This means that while the standard DIR command will produce a result very similar that command in command prompt, typing DIR /S for example will only produce an error in PowerShell, unless there happens to be a directory called S (PowerShell recognises a forward or a back slash as a path separator, not a parameter switch).
How do your Excel skills stack up?
Test NowNext up:
- The New IFS() and SWITCH() Functions in Excel
- The Change Cycle
- Persistent chat server role in Skype for Business
- Talking Tactics
- Excel Keyboard Shortcuts
- Leaping over communication hurdles
- More PowerShell Constructs and Loop Management
- Corruption found in Professional Development training company
- Using a model in your AngularJS form
- Why is it so hard to apologise?
Previously
- Do you Kanga?
- Windows 10 Command Prompt Shortcut Keys
- Skype for Business Server Architecture
- My thoughts on the Moto 360 SmartWatch
- How-To Series: Photoshop CC Intelligent Upsampling
- The Agreement Frame: Solving Complex Arguments
- Tips and Tricks with Nintex Forms
- 3 Simple Pie Chart Tricks
- Streaming Xbox One to Windows 10
- InDesign - Data Import Feature