Extract variables and functions out of PS Studio in order to share?

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Extract variables and functions out of PS Studio in order to share?

Post by stevens »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: 5.4.136.0
32 or 64 bit version of product: 64
Operating system: W2K12R2
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***
Hi,

I have an approach I would like to have your view on, the idea in bulletpoints:

*I have 1 globalvariables.ps1 which I load in my $profile and has all servers etc like $sccmserver, $smtpserver ...
*use the same globalvariables in my Powershell project
*use a specific psprojectvariables.ps1 for specific variables like $version, $creatorofproject etc
*I work with a lot of modules in my own PS => get all hard coded variables out there and depend on the variables loaded in globalvariables.ps1
+ add a line if $scriptroot\globalvariables.ps1 then load this, so I can easily share the script (just copy my globalvariables in the module)
*create small powershell script to remove all values from my globalvariables.ps1 so I can always use the globalvariables.ps1 I use for my own script in the globalvariablese.ps1 of the PS project
*copy over all my modules to the PS project so I do not need to add them each time I need a specific function
*remove all functions in my current PS project because I will load them from the modules
*share the PS project and keep only vital data (which should not be changed otherwise the project does not work) in an exe

Will be quite some effort so would appreciate your input before I start doing this :-).
J.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Extract variables and functions out of PS Studio in order to share?

Post by davidc »

I moved this topic to the Windows PowerShell forum so the community can contribute and provide best practices advise.

Typically, a module is a good way to go when you have to share a code base. As for creating the module, PowerShell Studio makes it easy with the New Module from Functions feature:

https://www.sapien.com/blog/2014/07/09/ ... -a-module/

Or import functions into an existing module or script:

https://www.sapien.com/blog/2016/03/07/ ... ew-part-3/
David
SAPIEN Technologies, Inc.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked