Vote count:
0
I'm trying to run a Powershell script from a batch file. After getting help here on the ps file (thanks again to TheMadTechnician!), 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 a WIndows2003 server, SP2, and it's 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.
Can anyone please give me some advice? I'm new to Powershell, and my boss wants this up and running asap. Thanks in advance!!
Calling Powershell script from batch file
Aucun commentaire:
Enregistrer un commentaire