Powershell script does not execute when being run in a folder with special character, for example C:\Test'1. If I run the powershell command from there, there is no issue, but executing the ps1 does not work.

Guillaume Archambault 1 Reputation point
2020-07-22T14:04:18.577+00:00

Powershell script does not execute when being run in a folder with special character, for example C:\Test'1. If I run the powershell command from there, there is no issue, but executing the ps1 does not work.

I tried it with multiple type of script, on multiple machines and always same behavior. As soon as I rename the folder to remove the special character, it works fine.

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,444 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Dave Patrick 426.4K Reputation points MVP
    2020-07-22T14:30:56.677+00:00

    May take some special handling if the apostrophe is really needed.
    https://devblogs.microsoft.com/scripting/how-can-i-connect-to-a-folder-when-theres-an-apostrophe-in-the-folder-name/

    --please don't forget to Accept as answer if the reply is helpful--

    0 comments No comments

  2. Rich Matheisen 45,591 Reputation points
    2020-07-22T14:47:24.677+00:00

    From "help about_Quoting_Rules":

    Quotation marks are used to specify a literal string. You can enclose a string in single quotation marks (') or double quotation marks (").

    Having only one single quote doesn't enclose anything. It only denotes the beginning of a literal string.

    To run your example, try .\"c:\Test'1\xxx.ps1"

    0 comments No comments