Ironman Software Forums
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
Discuss this ArticleThe using statement can be used for referencing namespaces, importing modules or loading assemblies. The using statement must appear at the top of the script.
When specifying the using with a namespace, it will allow you to use just the type name when creating objects or referencing static methods or properties within you script. It can thus shorten the script significantly.
using namespace System.IO
$Bytes = [File]::ReadAllBytes('C:\myFile.txt')
[FileInfo]::new('c:\myFile.txt')
Instead of using Import-Module, you can specify a using statement to import modules. Doing so will also import all PowerShell classes defined within the root module of the module.
using module MyModule
You can also use using to load .NET assemblies.
using assembly C:\myDll.dll
Find this useful? Please consider sharing this article. Have a question about PowerShell? Contact us and we'll write a post about it.
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.