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:
32 or 64 bit version of product: 64
Operating system: win7
32 or 64 bit OS: 64
*** Please add details and screenshots as needed below. ***
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
I have a number of projects with multiple psf files that call common functions.
I have bundled all the common functions into a sinlge ps1 file which is part of every project and that works.
However, I would like to 'convert' my ps1 file to a standard PS module (psm1).
This would simply involve renaming the file as a psm1 and moving to the standard ps module path.
I could add an 'Import module commonfunctions' to all my mainform.psf scripts but as modules are imported automatically, that would not be necessary.
I have two questions:
If I compile my project to an exe file and give it to someone, would they need the psm1 commonfunctions module in their module path? Im thinking not as the common function code is drawn in at compile time? IOW, the commonfunctions module is only required on the machine where I compile the project into an exe?
The reason I ask is that my projects contain AD cmdlets and for the compiled exes to work they have to have the activedirectory modulke installed. Im guessing that this is because AD modules are binaries rather than script code or something like that.
Second question:
Are standard psm1 files the 'best practice' for implementing common functions across multiple projects?
Thanks
David
Implementing common functions
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Implementing common functions
Modules are a good way to reusing functions across multiple scripts and it can be updated separately from the scripts themselves. But using a module means you will need to make sure that module is installed on the target machines.
You can handle distribution the different ways:
1. You could create an installer for your module and use it to distribute the file to the necessary machines.
2. Manually install the modules on the target machine.
3. Or you can distribute the shared psm1 or ps1 file with your executable and dot source it from your script or have the script install the module into a PSModulePath folder if not present.
If you don't want to deal with the extra files and distribution, your best bet would be to leave the file as part of your project. In the end, you need to decide what works best for your particular situation. On the other hand, if other people use your functions, a module is probably the best method for sharing your functions.
You can handle distribution the different ways:
1. You could create an installer for your module and use it to distribute the file to the necessary machines.
2. Manually install the modules on the target machine.
3. Or you can distribute the shared psm1 or ps1 file with your executable and dot source it from your script or have the script install the module into a PSModulePath folder if not present.
If you don't want to deal with the extra files and distribution, your best bet would be to leave the file as part of your project. In the end, you need to decide what works best for your particular situation. On the other hand, if other people use your functions, a module is probably the best method for sharing your functions.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.