0

I am having the following sample enum in my Mvc application and I need to reuse it in Power-Shell.

namespace namespace_name  
{
   public enum test  
   {  
      sample1,  
      sample2  
   }  
}

I need to use the above enum in PowerShell. I have come across the following link, https://social.technet.microsoft.com/wiki/contents/articles/26436.how-to-create-and-use-enums-in-powershell.aspx .

I don't know how to use the enum defined by us, please provide a way to use this in Power-Shell.

4
  • 1
    Import the dependency and then you can use the fully qualified name to access it (eg: [namespace_name.test.sample1]) I think Commented Jun 21, 2017 at 10:01
  • 1
    What do you mean "I don't know how to use the enum"? The Technet article you linked even has an example. Commented Jun 21, 2017 at 10:24
  • 1
    @Icepickle almost, [namespace_name.test]::sample1 Commented Jun 21, 2017 at 10:35
  • @MathiasR.Jessen Thanks, my knowledge of powershell is extremely rusty :) Commented Jun 21, 2017 at 10:35

1 Answer 1

2

The link in your question has the answer...

PowerShell allows to define a enum using the Add-Type cmdlet. Once the enum type has been added to the console environment, it can not be removed or re-defined? Closing and re-opening the console will remove the enum.

Enums are used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.

Add-Type -TypeDefinition @"
   public enum test
   {
      sample1,
      sample2
   }
"@
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.