Changing the name of the function Main in Startup.pss

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 5 years and 8 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
Matthew.miller
Posts: 2
Last visit: Mon Nov 09, 2020 3:04 pm

Changing the name of the function Main in Startup.pss

Post by Matthew.miller »

Is there a way to change the name of the function main in the startup.pss? If I change it, PowerShell Studio automatically recreates function Main {}.

Product, version and build: 2018 (5.5.152)
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Changing the name of the function Main in Startup.pss

Post by davidc »

The generated script specifically looks for the Main function as an entry point to the project. That is why it inserts if, when you rename the functions.

Is there a reason you wish to rename the function?
David
SAPIEN Technologies, Inc.
User avatar
Matthew.miller
Posts: 2
Last visit: Mon Nov 09, 2020 3:04 pm

Re: Changing the name of the function Main in Startup.pss

Post by Matthew.miller »

David, thanks for the quick response.

We are using centralized logging for our scripts that uses the function name to know where the logged message was run. Because 'main' is so generic, we want to change the name of the 'main' function to 'scriptName_main' for our logging purposes. If there isn't a way to update a project to allow us to change the name of 'main', I suppose I can change it after the project compiles. However, this isn't ideal because we have to remember to do it every time the script has been updated.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Changing the name of the function Main in Startup.pss

Post by davidc »

I would recommend creating a secondary function that is called from the Main function for logging purposes. That way you don't have to modify the Main function's name.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 8 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.