How to deal with space in the path

AATester 26 Reputation points
2022-04-07T08:25:07.367+00:00

Hi,

I have a below path that has space between My and Test which I cannot change at the moment.

The script is unable to execute run the file from PickupTest.ps1. However, I do see that powershell flickers which means it opens to try to pick up the file but nothing happens after. Someone suggested me to find a way to deal with space in the path to solve the problem. Any help would be appreciated.

WshShell.Run("powershell -file \"" + pathvar + "\My Tests\PickupTest.ps1")

Thanks!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,435 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,476 Reputation points
    2022-04-13T15:50:42.407+00:00

    Hi @AATester

    Thanks for writing and I'm happy to help you today regarding running your power shell script.

    In case you want to run powershell.exe -File from the command line, you always have to set paths with spaces in double quotes ("").

    Also try using the Grave Accent Character () PowerShell uses the grave accent () character as its escape character. Just add it before each space in the file name. (You’ll find this character above the Tab key and below the Esc key on your keyboard.)

    WshShell.Run("powershell -file \"" + pathvar + "\*My `  Tests*\\PickupTest.ps1")  
    

    Here is a helpful page with information about Windows PowerShell

    https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/powershell

    ------------

    --If the reply is helpful, please Upvote and Accept as answer.--

    1 person found this answer helpful.
    0 comments No comments