Ich habe eine Abfrage wie wenn ich versuche, den Ausdruck, der einen Pfad mit Leerzeichen enthält, ausführen, bekomme ich einen Fehler wie folgt.In Powershell, Invoke-Ausdruck funktioniert nicht bei der Eingabe von Leerzeichen im Pfad
Code:
$path="E:\Test\My space\Log"
Invoke-Expression $path
E:\Test\My: The term 'E:\test\My' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ E:\Test\My space\Log
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (E:\Test\My :String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Könnten Sie mir bitte helfen, dieses Problem zu beheben.?
Das ist gleichbedeutend mit der Eingabe von 'E: \ Test \ My space \ Log' in die Konsole und das Drücken von Enter - was haben Sie erwartet? –
Jeder Pfad muss in Anführungszeichen gesetzt werden, so dass das obige wie folgt aussehen würde: "Invoke-expression" $ path "' –
Sie brauchen nicht 'Invoke-Expression'. '& $ path' wird gut funktionieren. –