Method for adding an existing Function into a Module Project

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
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.
This topic is 6 years and 2 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.
User avatar
xtraspecialj
Posts: 12
Last visit: Mon Mar 04, 2024 7:02 am

Method for adding an existing Function into a Module Project

Post by xtraspecialj »

In the Product Manual there is a great article on how to use the "New Module from Existing Functions" feature. I followed the instructions and finally centralized all of my functions into one module and I'm super-happy about it.

However, I just realized I left out a function and I'd like to add it in. I don't see any feature for updating the project to add in a function. Do I just have to manually put the function in the psm1 file and update the psd1 file myself, or is there a way to do it in the program that is similar to the "New Module from Existing Functions" feature?

I thought maybe using the Insert Function feature would work but it didn't. It just put the function in the file. I am completely new to modules and was hoping there was an automated way to update them with PS Studio like there was a way to create it. Am I wrong?


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: PowerShell Studio 2017, version 5.4.142
32 or 64 bit version of product: 64 Bit
Operating system: Windows 7 Professional
32 or 64 bit OS: 64 bit

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

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Method for adding an existing Function into a Module Project

Post by davidc »

You can use the Import Functions feature:

https://www.sapien.com/blog/2016/03/07/ ... ew-part-3/

As for automation, there is no scripted way of doing this with PowerShell Studio, other than using the import commands.
David
SAPIEN Technologies, Inc.
User avatar
xtraspecialj
Posts: 12
Last visit: Mon Mar 04, 2024 7:02 am

Re: Method for adding an existing Function into a Module Project

Post by xtraspecialj »

Thanks for the reply David. Yeah, I mentioned in my post that I already tried the Import Function feature and all that does is put the function into the file.

However, after more study I found out that the only other stuff to do beside putting the new function in the .psm1 file was to add the name of the function to the "Export-ModuleMember -Function" list at the end of that file. I then found out I have to do an "Import-Module -Force" on all of the remote machines to get them to reload the module file with the updated functions (I've got the module file and psd1 file saved on a remote share and I'm pointing all of the machines that I want to run my scripts on to this share location so that I now have 1 central place to manage all of my functions.

Even though it's a pretty easy to task to just copy/paste the function into the file and add the function name to that command, I do think it'd be cool if there was a built-in option to add existing functions to an existing module. That way PS Studio would have a way to both create a module from existing functions and update a module with existing functions.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Method for adding an existing Function into a Module Project

Post by davidc »

Yes, you have to update the Export-ModuleMember statement manually. PowerShell Studio does not modify this line because it doesn't know the user intent, therefore it leaves it up to the user to update the export statement.

On our TODO list, is to add an easy way to update the export statements for modules without manually updating the statement or the manifest.
David
SAPIEN Technologies, Inc.
This topic is 6 years and 2 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.