I have 3x scripts:
- C:\Powershell\Test1.ps1:
WRITE-HOST "My Name is" $MyInvocation.MyCommand.Name . "C:\Powershell\Test2.ps1" - C:\Powershell\Test2.ps1:
WRITE-HOST "My Name is" $MyInvocation.MyCommand.Name . "C:\Powershell\Test3.ps1" - C:\Powershell\Test3.ps1:
WRITE-HOST "My Name is" $MyInvocation.MyCommand.Name
This is the output:
PS C:\Powershell> .\Test1.ps1
My Name is Test1.ps1
My Name is Test2.ps1
My Name is Test3.ps1
I would like Test1.ps1 to INCLUDE the code within itself instead of calling them as scripts inside itself.
If possible, this is the sort of output I'd like:
PS C:\Powershell> .\Test1.ps1
My Name is Test1.ps1
My Name is Test1.ps1
My Name is Test1.ps1
Is this possible? The original Test1 script is called, so this should the name of the script throughout, regardless of what it then calls afterwards?
$MyInvocation.MyCommand.Namecontains a different script file then the file itself? Why do you want to do that? - Martin Brandl$MyInvocationwill not be consistent across multiple files. Maybe you can use another script to concatenateTest1.ps1,Test2.ps1andTest3.ps1? They would all be running in the same context then. - sodawillow