Check out the cloud & automation training courses that are developed by Art of Shell, who sponsored this video!

In PowerShell 5.0, the using statement enables two new, exciting scenarios! If you're using Windows 10, you already have PowerShell 5.0 available to you! Support for PowerShell 5.0 is also offered via the Windows Management Framework (WMF) package, for down-level operating systems including Windows 7, Windows 8, and Windows Server 2012 R2.

First of all, you can "import" .NET namespaces, similar to the C# language, so you don't have to type the full path to a .NET type. For example, instead of typing [System.Data.SqlClient.SqlConnection] every time you want to reference the SqlConnection .NET class, you can add a using statement for the System.Data.SqlClient .NET namespace. Once you've done this, you can simply reference the class like so: [SqlConnection].

The second scenario that the using statement enables in PowerShell is the ability to import PowerShell Classes from PowerShell modules! If you've created a module that defines one or more PowerShell Classes, you can import those classes from the module by adding a using statement to your PowerShell scripts. The proper syntax for this is: using module <moduleName>. Once you've "used" the module, you can then access the class definitions inside of it!

Watch this video for a demonstration about both techniques!

Cheers,

Trevor Sullivan

Microsoft MVP: Cloud & Data Center Management

Founder, Art of Shell

E-mail: trevor@artofshell.com