![]() ![]() ![]() The trick is that you have to put “& “ before the script path to actually run the script. If you simply try to run the script by enclosing the path to the script in double quotes you will just see the path spit back at you in the console, instead of actually running the script. Windows 8 Pro Tip: You can open the PowerShell console at your current directory in File Explorer by choosing File –> Open Windows PowerShell. So the typical work around for this is to open a PowerShell console and run the script by enclosing the path in double quotes. Run script path with spaces from PowerShell console So the path to the script I was trying to run is “C:\My Folder\My PowerShell Script.ps1”, but from the error you can see that it cut the path off at the first space. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The term ‘C:\My’ is not recognized as the name of a cmdlet, function, script file, or operable program. If they are lucky enough to press Print Screen at the right moment, or decide to open up a PowerShell console and run from there, they might see an error message similar to this: So the problem that the 90% of people are likely to encounter is that as soon as the script path has a space in it (either in the filename itself or in the directory path the file resides in), they will see the powershell console flash some red text at them for about 1/10th of a second before it closes, and they will be wondering why the script did not run or worse, they won’t know that it didn’t run (see the “Keep PowerShell Console Open” section below). Error message when trying to run a script whose path contains spaces This is probably how 90% of people run their PowerShell scripts power uses might run their scripts directly from the PowerShell command prompt. ![]() If you don’t mind opening in an editor as the default action, then to run the script you can just right-click on the script and choose “Open with” –> “Windows PowerShell”. ps1 files” option is checked (this might be called “Always use the selected program to open this kind of file” or something else depending on which version of Windows you are using). Just right-click on the script, go to “Open with” –> “Choose default program…”, and then select Windows PowerShell, making sure the “Use this app for all. If this bugs you, it’s easy enough to fix. The default Windows action when you double click on a PowerShell script is to open it in an editor, rather than to actually run the script. Make running (instead of editing) the default PowerShell script action Most of the other content in this post can be found elsewhere, but I provide it for context and completeness. Most people will likely find the “Run script path with spaces from File Explorer” (to be able to double click a PS script whose path contains spaces to run it) section below the most helpful. Fix Problem Where Windows PowerShell Cannot Run Script Whose Path Contains Spaces ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |