Search code examples
powershelldirectoryescapingquoting

Set Location in PowerShell that contains a ampersand (&)


How do i set my directory using PowerShell to the below location ?

W:\B&M\Store Segmentation\Pete\Python

I tried using:

PS > Set-Location -Path W:\B"&"M\Store Segmentation\Pete\Python

Solution

  • Use " double quotes or ' apostrophes as follows:

    Set-Location -Path "W:\B&M\Store Segmentation\Pete\Python"
    

    or

    Set-Location -Path 'W:\B&M\Store Segmentation\Pete\Python'
    

    Read About Quoting Rules for explanation.