Click here to Skip to main content
15,670,442 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I want to pass below string parameter from cmd to ps1. The string that I want to pass has spaces in between. As a result, I believe, it is not able to read the entire string.

string parameter -
\\\afhb-emea\GROUP\IND\IT\SharedServices\Pune Ravet\Test

Please help me how can I pass such string parameter containing spaces in between so that I can correctly read it in the powershell.

What I have tried:

I am passing string parameter to ps1 from cmd as below :

powershell.exe archive_files.ps1 -path "\\\afhb-emea\GROUP\IND\IT\SharedServices\Pune Ravet\Test" -days 0 -months 0 -years 2

I am reading above string in powershell script as below :

param (
write-host "Files to delete from Path is $path"

It is giving below output once I run it :

Files to delete from Path is \\\afhb-emea\GROUP\IND\IT\SharedServices\Pune
Updated 24-Aug-22 6:12am
Comments 24-Aug-22 8:35am    
Try the ideas which were posted @

1 solution

Just put it in double quotes:
Foo.ps1 "\\\afhb-emea\GROUP\IND\IT\SharedServices\Pune Ravet\Test"
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900