At Microsoft Ignite (around 8:15 min), we announced the Public Preview of PowerShell in Azure Cloud Shell. A unique feature of PowerShell experience in Azure Cloud Shell is navigation of Azure resources via the Azure drive (Azure:). Today, we are making this feature available on PowerShell Gallery as well as making the source code available on GitHub. This enables you to navigate Azure resources from any machine running Windows PowerShell 5 or higher.
Simple Hierarchy in PowerShell (SHiPS) – An Easier Way to Build PowerShell Providers
AzurePSDrive is built on top of an abstraction layer – SHiPS, which simplifies developing PowerShell providers. SHiPS is also a PowerShell provider that exposes datastores in a hierarchical manner (like a file system). In other words, the data in your datastore can be treated like files and directories so that a user can navigate data via
Writing a PowerShell provider can be challenging as one needs to implement various methods exposed by the base PowerShell provider classes and interfaces to make it work. SHiPS simplifies this experience by exposing fewer methods and enables PowerShell providers to be written using PowerShell classes syntax.
With SHiPS, you can:
- Author PowerShell providers using PowerShell classes as well as C#
- Navigate the data store using
- Build navigation model that works on both Windows PowerShell (.Net FullCLR) and PowerShell Core (.Net CoreCLR)
Built on Top of Community Contribution
SHiPS is built on top of P2F (PowerShell Provider Framework), created by Jim Christopher, which does the heavy lifting for the implementation of SHiPS. SHiPS with P2F provides the simplification of developing PowerShell provider.
Once a SHiPS-based navigation is defined, such as AzurePSDrive, users can easily create a PSDrive by installing the modules from the PowerShell Gallery.
Update-Module AzureRM # refresh AzureRM modules to the latest version Install-Module AzurePSDrive # will install SHiPS as its dependency Import-Module AzurePSDrive Login-AzureRmAccount New-PSDrive -Name Azure -PSProvider SHiPS -root 'AzurePSDrive#Azure' cd Azure: PS Azure:\>dir
In this example,
AzurePSDrive is a PowerShell module written using PowerShell classes. It defines a PowerShell class called
Azure as the PowerShell provider root. The syntax for
root parameter of PSDrive for SHiPS provider is
New-PSDrive, SHiPS loads the module,
AzurePSDrive, and creates an instance of an ‘Azure’ object. When a user types
dir, SHiPS calls GetChildItem() implemented within the Azure class.
Call to Action
Principal Software Engineer