Thanks for your help. So I have a problem with my script. I am trying to convert my script from batch to PowerShell, mostly just to try to learn it so I am completely new to PowerShell but I know other languages so I am decent at programming. My script creates a kivaCommands.txt
file that is then used in Plink to be executed on the server. My batch script works fine with Plink but when I converted to PowerShell the Plink line errors on the -m
switch. I get
sh: ■e: not found
I get this error no matter what commands are in the txt file, even if the file is empty. The Plink line works fine if I pass it a single command to execute. This is the code I'm having trouble with.
$hostLogin = "myServer"
$passwd = "myPassword"
$command = "H:\kivaCommands.txt"
C:
cd \
cd "Program Files (x86)\PuTTY"
./PLINK.EXE -ssh $hostLogin -P 22 -pw $passwd -m $command
The cd
commands were the only way I could get it to work. I tried all other ways of giving the whole path and creating a variable for the path but Plink would not execute.
So after more troubleshooting, I have narrowed it down to the file created. If I manually create the file it works fine but my script creates the file before calling Plink. I have tried three different ways to create the file
"exit ^| sqlplus / @kiva_extract $assessorYear" | Set-Content H:\kivaCommands.txt -Encoding Unicode
"exit ^| sqlplus / @kiva_extract $assessorYear" | Out-File H:\kivaCommands.txt -Encoding Unicode
"exit ^| sqlplus / @kiva_extract $assessorYear" > H:\kivaCommands.txt
The file creates fine and looks right but Plink cannot open correctly.