PowerShell Module: Creating PowerShell Module with Class and Objects vs Function

Welcome Forums General PowerShell Q&A PowerShell Module: Creating PowerShell Module with Class and Objects vs Function

Viewing 1 reply thread
  • Author
    Posts
    • #199079
      Participant
      Topics: 1
      Replies: 0
      Points: 80
      Rank: Member

      I am on my way to create a custom powershell module for one of our recovery products. Currently it is been developed with the help of powershell functions. I am thinking of experimenting the same with the help of PowerShell class and object constructs, but i am not sure if i should do it all or not.

      Please help me to understand following-

      1. Should we create PowerShell module with the help of Class and Object?
      2. If Yes, Than Why?
      3. what are the benefits of having Class and Objects compare to PowerShell functions?
      4. Does it help us in creating custom Object types efficiently and manage the objects in effective way?
      5. if not, then what are the drawbacks of having module written as Class and object compare to Function.

      Thanks,

      Jatin

    • #199181
      Moderator
      Topics: 3
      Replies: 223
      Points: 1,221
      Helping Hand
      Rank: Community Hero

      Should we create PowerShell module with the help of Class and Object? If Yes, Than Why? what are the benefits of having Class and Objects compare to PowerShell functions? Does it help us in creating custom Object types efficiently and manage the objects in effective way? if not, then what are the drawbacks of having module written as Class and object compare to Function.

      Hi there,

      Please see my comments below…

      1. It is not mandatory to write PowerShell classes to create the modules, it is completely up to you. But PowerShell modules will not export the classes, you need to create an object for that class in the module itself and export it using functions.
      2. You can create custom type objects with your own members (Properties, Methods & etc.,)
      3. Yes

      Thank you.

Viewing 1 reply thread
  • The topic ‘PowerShell Module: Creating PowerShell Module with Class and Objects vs Function’ is closed to new replies.