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)
Changing the name of the function Main in Startup.pss
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.
- Matthew.miller
- Posts: 2
- Last visit: Mon Nov 09, 2020 3:04 pm
Re: Changing the name of the function Main in Startup.pss
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?
Is there a reason you wish to rename the function?
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- Matthew.miller
- Posts: 2
- Last visit: Mon Nov 09, 2020 3:04 pm
Re: Changing the name of the function Main in Startup.pss
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.
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.
Re: Changing the name of the function Main in Startup.pss
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.
SAPIEN Technologies, Inc.