pass deluge torrentname to powershell via bat script - powershell

I've install deluge and would like to use the execute plugin to send a pushover message via powershell
set torrentname=%2
powershell.exe -ExecutionPolicy Unrestricted -File C:\Pushover-DelugeNotify.ps1 %torrentname%
I've created the above yet for some reason it doesn't work I see a cmd window flash up and close, yet no message comes through.
I've tried
powershell.exe -ExecutionPolicy Unrestricted -File C:\Pushover-DelugeNotify.ps1 "Test"
which works no problem.
whay am I doing wrong?

If you don't have other arguments on your batch, you should use "set torrentname=%1"
set torrentname=%1
powershell.exe -ExecutionPolicy Unrestricted -File C:\Pushover-DelugeNotify.ps1 %torrentname%

Related

Powershell: Invoke a session as Administrator

I am trying to run my script as a ADMIN user and install the certificates, but it only works if I run it from the command line as a Administrator. If I trigger my bat file from the other script it is installing the certificates as a local user.
SET PowerShellScriptPath='<FilePath>\File.ps1'
SET CertPath=%~dp0NewCSC.cer
start PowerShell.exe -ExecutionPolicy Bypass -Command "& {Set-ExecutionPolicy Bypass -Force -Scope LocalMachine}" 
timeout 05
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& %PowerShellScriptPath% %CertPath%"
Is it coz of I am using Powershell.exe to invoke for 2 times for every line its taking it as a local user? please help me out here.

batch-file pauses after execution of powershell command

What I am trying to do is to set -ExecutionPolicy (allow scripts) for the actual process (cmd.exe)
If a write this command in cmd.exe (as Administrator):
PowerShell.exe -ExecutionPolicy Unrestricted
Output is:
Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
Lernen Sie das neue plattformübergreifende PowerShell kennen – https://aka.ms/pscore6
Than I put on this command:
PowerShell.exe -Command "SomePowerShellScript.ps"
And all works.
If I try the same from a batch-file, it pauses after the first command.
The reason why I use the first command and not the Powershell specific with Set-ExecutionPolicy is described by Microsoft:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-5.1
PowerShell.exe -ExecutionPolicy Unrestricted
--> sets ExecutionPolicy to cmd and powershell (script can be started)
PowerShell.exe -Command Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
--> sets Policy only on actual powershell.exe process (script is not allowed to start)
And for clarifing I don't want to set execution policy to Unrestricted for LocalMachine/CurrentUser if possible.
For explaning this problem, the batch-file is only for "lazy" people to directly start the Powershell-Script without having to set ExecutionPolicy (So it works by double clicking).
Has anyone an idea why the batch-file pauses after the first command (I also tried it with call powershell.exe)?
Thanks for a response :).
The apparent pause is a result of PowerShell.exe -ExecutionPolicy Unrestricted actually entering an interactive PowerShell session, which you must manually exit (aside from that, the execution policy is set for that session (process) only).
If you place -ExecutionPolicy Unrestricted (or -ExecutionPolicy Bypass) before a -File argument, the execution policy is set - for the process only - before execution of the script file passed to -File is attempted, and execution should succeed (unless a group policy preempts overriding the persistently configured execution policy on the command line:
powershell.exe -ExecutionPolicy Unrestricted -File SomePowerShellScript.ps1
You can also use -Command, but note that this changes the interpretation of the arguments; notably, you must then use .\SomePowerShellScript.ps1 to refer to the script to execute.
See this answer for more information.

I need help fixing my batch file in execution to powershell

I'm trying to call these powershell scripts in a batch file, as follows:
Powershell.exe -executionpolicy remotesigned -File d:\1.ps1
Powershell.exe -executionpolicy remotesigned -File d:\2.ps1
Powershell.exe -executionpolicy remotesigned -File d:\3.ps1
Powershell.exe -executionpolicy remotesigned -File d:\4.ps1
I run that batch file and is giving me the following error for 2.ps1,3.ps1 and4.ps1
the argument d:\2.ps1 for the parameter -file doesnt exist. Provide the path of access to the file d:\2.ps1 (2.3.4) existent as argument for the parameter -file"
The files are in the drives where i am calling them, 3 and 4 fails to execute because are connected to script 2.ps1.
I dont know what is the problem in calling 2.ps1, after 1.ps1 because it is the same commnd, if I execute the files manually, they run just fine.
Try calling it like this:
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "d:\1.ps1"

Powershell Start-Process works but not from .ps1 script

If I paste this into Powershell blue window it runs fine and launches the program
Start-Process “C:\Program Files (x86)\Engine Pro\engine.exe” -ArgumentList "#21#”;
but if I try to run the same command in a script, run.ps1 script, that launches from a scheduled task in Windows, it does nothing
PowerShell.exe -windowstyle hidden -NoProfile -ExecutionPolicy Bypass C:\run.ps1
Does it have something to do with the -ExecutionPolicy Bypass? Do I have to have an Execution policy in the script as well? I really don't know what that is. I know what -windowstyle hidden is but -NoProfile -ExecutionPolicy Bypass I'm not sure why that is there, just found it on another page, but it's all working except for the program launching from within the script.
Thank you.
& Start-Process "C:\Program Files (x86)\Engine Pro\engine.exe" -ArgumentList "#21#";

Run Powershell script in windows Task Scheduler(Windows 7)

Hi I've got a Script and are trying to start it in Task Scheduler.
this poses Two problems for me.
is that the script will activate a Application that requires the GUI to be running and shown. so how can I make Task Scheduler to log in to windows automatically at a specific time. The computer will never/rarely be turned off or rebooted.
2.
I have yet to Successfully start a Powershell script from the Task Scheduler. I've tried Following:
powershell.exe -noexit -executionpolicy bypass -command &'Y:\Run Test\StartPowershellScript.ps1'
And
powershell.exe -noexit -ExecutionPolicy Bypass -File 'Y:\Run Test\StartPowershellScript.ps1'
And a variation of the above.
powershell.exe -noexit -ExecutionPolicy Bypass &'Y:\Run Test\StartPowershellScript.ps1'
and I've tried some variations with and without &"" &'' & and so on.
now I'm not really sure if it can be done. but I hope I can get some help here.
Edit 1.
I just tried the following.
powershell -noexit -ExecutionPolicy Bypass &'Y:\Run Test\StartPowershellScript.ps1'
after I did this in powershell.
set-executionpolicy -scope Process -executionPolicy Unrestricted -force
set-executionpolicy -scope CurrentUser -executionPolicy Unrestricted -force
set-executionpolicy -scope LocalMachine -executionPolicy Unrestricted -force
However How do I make sure that this will persist after the computer has been rebooted ?
Edit 2.
as it seems I can't make Scheduled task log in or unlock the computer, is there Anyway to set up a task to run at a specific time to log in to the computer so the scheduled task can run at this time ?
You can't log into the GUI with a scheduled task. Enable automatic logon if you need an interactive desktop.
Remove -NoExit from the argument list, otherwise PowerShell will keep running after the script completes. Also replace your single quotes with double quotes.
The execution policy is persistent unless it's superseded by a local or group policy (in which case Set-ExecutionPolicy should throw an error) or you're logged in with a temporary profile.
If that doesn't help you need to provide more details. Doesn't the task start at all? Do you get an error? What do the task history and eventlog say? What is the output of Get-ExecutionPolicy?