Before I go any further, my experience with Powershell amounts to only 2 days.
I am trying to call a powershell script from the command line with four parameters added to the command. The powershell script simply cleans a CSV file and makes a copy of the file at every stage of cleaning.
The variables a
, b
, c
and d
in the script relate to the new filenames (including the full address).
PowerShell Script
param(
[string]$a,
[string]$b,
[string]$c,
[string]$d
)
Get-Content $a | ForEach-Object { $_ -replace """""""""""","""""" } | Set-Content $b -Force
Get-Content $b | ForEach-Object { $_ -replace """""""","""" } | Set-Content $c -Force
Get-Content $c | ForEach-Object { $_ -replace """""","" } | Set-Content $d -Force
Command Script
The command script below is what I am trying to run in cmd
(note: I have taken out the real addresses).
powershell.exe '\\somefileaddress\CleanData.ps1'
-a "\\someaddress\DrFA-C.csv"
-b "\\someaddress\DrFA-C_2.csv"
-c "\\someaddress\DrFA-C_3.csv"
-d "\\someaddress\DrFA-C_4.csv"
The error message i am getting is:
You must provide a value expression on the right hand side of the '-' operator.
I'm fairly sure that the problem isn't with your script but with how you're calling it. This works for me (without the newlines which were inserted for clarity):
powershell.exe -Command "& '\\somefileaddress\CleanData.ps1'
-a '\\someaddress\DrFA-C.csv'
-b '\\someaddress\DrFA-C_2.csv'
-c '\\someaddress\DrFA-C_3.csv'
-d '\\someaddress\DrFA-C_4.csv'"