I'm trying to run a PowerShell script from a batch file, and it runs successfully on my machine. However when I put it on the server, it throws this error:
"Missing expression after unary operator '-'.
At line:1 char:2
+ -E <<<< xecutionPolicy remotesigned -file 'E:\Misdemeanor
Queue\Concatenate.ps1'
I've tried different combinations of the execution policy, but nothing seems to work. I have to run this on Windows Server 2003, SP2, and it uses v1.0 of PowerShell (which is what I wrote this in). There is a space in the folder name that houses the batch file & ps1 file. Here is the batch file that calls the ps1 file named Concatenate.ps1:
- @echo off &setlocal
del "E:\Misdemeanor Queue\Index3.txt"
set "search=.tif"
set "replace=|"
set "textfile=index2.txt"
set "newfile=Index3.txt"
(for /f "delims=" %%i in ('findstr "^" "%textfile%"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
type "%newfile%"
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'E:\Misdemeanor Queue\Concatenate.ps1'"
Here is the concatenate.ps1 file:
$File1 = Get-Content "E:\Misdemeanor Queue\Index3.txt" $File2 = Get-Content "E:\Misdemeanor Queue\index1.txt" $File3 = @() For($a=0;$a -lt $File1.count;$a++){ $File3+=$File1[$a].trim()+$File2[$a].trim() } $File3 | Out-File "E:\Misdemeanor Queue\indexFINAL.txt"
It's supposed to call this ps file, concatenate the Index3 file and the Index1 file, and create a txt file called indexFINAL.
What should I do?