Is there a “template-sort-of-thing” in powershell?

Welcome Forums General PowerShell Q&A Is there a “template-sort-of-thing” in powershell?

Viewing 2 reply threads
  • Author
    Posts
    • #225144
      Participant
      Topics: 41
      Replies: 113
      Points: 647
      Rank: Major Contributor

      I have a code like this that is repeated multiple times in each of my conditional statements/cases. i have 3 conditions…for now, and everything works perfectly, but im mulling reformatting the script for easier reading.

      One of the ways ive thought is to make a function, but the problem is that, i have a while loop that is intended for a specific scenario in each conditional statement that dequeues from a Queue containing some column names from a file.

      so based on the code below that i want to put in some sort of template, i cant think of how this could work because as you can see, $tb stands for $table, which is what im opening prior to the conditional statements in my code. if i were to include everything regarding the server connection and table in a function, that means when i pass the “function” containing the code to the while loops, it will be creating/instantiating the table every iteration, which wont make sense and wont work anyways.

      so i am thinking of using something like annotations, something like a template which wont expect to return anything or need reasonable arguments like a function otherwise would. The question is, does something like that exist?

      This is the code that is the same across all my while loops that i would like to “store” somewhere and just pass it to them:

      [/crayon]

      think of it like a puzzle piece that would fit right in when requested to do so in the while loops to complete that “puzzle”

      related

    • #225195
      Participant
      Topics: 12
      Replies: 547
      Points: 1,345
      Helping Hand
      Rank: Community Hero
    • #225267
      Participant
      Topics: 41
      Replies: 113
      Points: 647
      Rank: Major Contributor

      As mentioned here https://stackoverflow.com/questions/61569760/is-there-a-function-like-thing-that-can-act-as-a-template I recommend you use a helper function..

      i went with your recommendation, thanks 🙂

Viewing 2 reply threads
  • The topic ‘Is there a “template-sort-of-thing” in powershell?’ is closed to new replies.