Forum Discussion
John_Dodo
Dec 21, 2022Copper Contributor
Retrieve executed script information the best way
Hello, I have this piece of code at the begining of most of my script. $ScriptFolderPath = $PSSCRIPTROOT
$ScriptFolderName = (get-item $ScriptFolderPath ).Name
$BaseFolder = (get-item $Sc...
John_Dodo
Jan 24, 2023Copper Contributor
Sorry for the late answer.
I think my question was not clear enough.
Basically I need to set these variables because I want to use them in my scripts (so transcript isn't an option). But as you can see in my code I am using different ways to get the said values.
My question was, is there any standardize way to all the values? (Using the same logic for all of them). Still not clear maybe...
Jan 24, 2023
Ah, you want to read them from somewhere in your scripts? Or do you want to output them? Confused 😄
- John_DodoJan 24, 2023Copper ContributorLet say script $ScriptFolderPath, I use it to call CSV files located next to the called script.
$ScriptNameNoExtension, I use it to generate log files with the name of the script. Etc- Jan 24, 2023Do you want to insert these into your script as a Code snippet or something? Like a template script?
- John_DodoJan 24, 2023Copper ContributorTemplate script if you will yes.
The section of code I have written in my first message is at the beginning of all my main scripts.
I just want to know what is best to retrieve these values. Using $PSSCRIPTROOT method, using $myinvocation or something else.