Ich habe 3x Skripte:Powershell - Andere Methode der Codeeinbindung?
- 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
Dies ist die Ausgabe: PS C:\Powershell> .\Test1.ps1 My Name is Test1.ps1 My Name is Test2.ps1 My Name is Test3.ps1
Ich möchte, dass Test1.ps1 den Code in sich selbst INCLUDE, anstatt sie als Skripte in sich selbst zu nennen.
Wenn möglich, ist dies die Art von Ausgang würde Ich mag: PS C:\Powershell> .\Test1.ps1 My Name is Test1.ps1 My Name is Test1.ps1 My Name is Test1.ps1
ist das möglich? Das ursprüngliche Test1-Skript wird aufgerufen, also sollte dies den Namen des Skripts durchgängig, unabhängig davon, was es danach aufruft?
Sie wollen im Grunde, dass ' $ MyInvocation.MyCommand.Name' enthält eine andere Skriptdatei als die Datei selbst? Warum willst du das machen? –
'$ MyInvocation' ist nicht konsistent über mehrere Dateien hinweg. Vielleicht können Sie ein anderes Skript verwenden, um 'Test1.ps1',' Test2.ps1' und 'Test3.ps1' zu verketten? Sie würden dann alle im selben Kontext laufen. – sodawillow