Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a namespace within a PowerShell script

Tags:

powershell

I would like to utilize my own custom namespaces in a PowerShell .ps1 script or a .psm1 module. Is this possible? If so, what is the syntax to do this?

I found a related link here: Breaking the Powershell namespace limit of global,script

It seems like I will need to make my own custom object, or possibly use a custom associative array for this?

I would like to be able to call my function like this:

[MyCoolNamespace]::Get-CrazyYall
like image 484
Josh Petitt Avatar asked Nov 12 '14 17:11

Josh Petitt


1 Answers

A module name is similar to a namespace. For example:

Microsoft.PowerShell.Core\Get-Command

is the same as

Get-Command

Normally you don't use module qualified names when invoking commands (cmdlets, functions, or aliases), but it comes in handy if you do have a conflict or want to be 100% certain you are invoking the function you meant to.

like image 104
Jason Shirk Avatar answered Oct 19 '22 05:10

Jason Shirk