Hello, I'm brand new to XYplorer. So far I'm loving it!
Can someone please tell me how I can execute a PowerShell script from XY? Maybe from a user button? I have a .ps1 script which simply outputs "hello world" to a file. This is how I've been trying:
$scriptPath = self("path");
$cmd = "Powershell -NoExit -File "C:\Users\ra-bartonbf\PowerShell\HelloWorldFile.ps1"";
msg($cmd);
run($cmd);
-Thanks
How to execute a PowerShell script from XYplorer?
Re: How to execute a PowerShell script from XYplorer?
Welcome to the forum.
The quoting is wrong.
The quoting is wrong.
Code: Select all
$cmd = """Powershell"" -NoExit -File ""C:\Users\ra-bartonbf\PowerShell\HelloWorldFile.ps1""";
run $cmd;
One of my scripts helped you out? Please donate via Paypal
Re: How to execute a PowerShell script from XYplorer?
Within a user defined button, the $cmd syntax did not work. However, this runret command does work. Is this syntax acceptable to use?
-Thanks
runret("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\bernie\PowerShell\test.ps1");
//$cmd = """Powershell"" -NoExit -File ""C:\Users\bernie\PowerShell\test.ps1""";
//run $cmd;
-Thanks
runret("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\bernie\PowerShell\test.ps1");
//$cmd = """Powershell"" -NoExit -File ""C:\Users\bernie\PowerShell\test.ps1""";
//run $cmd;
Re: How to execute a PowerShell script from XYplorer?
It does work from an CTB (but you didn't copy the indentation from within the code tags correctly).
In your first example you wanted the powershell to stay open to see the command output while now
you want to hide it completely?
Is your new command syntactically correct? Yeah. But recommended? Not really.
- The powershell directory is in the path anyway. No need to use the full path to call it
- Much more important: It breaks in the same second your script name or path contains a space
In your first example you wanted the powershell to stay open to see the command output while now
you want to hide it completely?
Is your new command syntactically correct? Yeah. But recommended? Not really.
- The powershell directory is in the path anyway. No need to use the full path to call it
- Much more important: It breaks in the same second your script name or path contains a space
One of my scripts helped you out? Please donate via Paypal
Re: How to execute a PowerShell script from XYplorer?
Using the run command does not work for me. I've tried various permutations of the $cmd = line, to no avail. The runret command does work. I can't see what I am doing wrong.
-Thanks
$cmd = """powershell.exe"" -NoExit -File ""C:\Users\ra-bartonbf\PowerShell\HelloWorldFile.ps1""";
run $cmd;
runret("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\ra-bartonbf\PowerShell\HelloWorld.ps1");
-Thanks
$cmd = """powershell.exe"" -NoExit -File ""C:\Users\ra-bartonbf\PowerShell\HelloWorldFile.ps1""";
run $cmd;
runret("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\ra-bartonbf\PowerShell\HelloWorld.ps1");
Re: How to execute a PowerShell script from XYplorer?
Neither can I if you don't show what exactly you're doing? You paste the two codelines. Fine. Where? In the "On left click" field directly? After pressing the "Edit..." button? The single line edit field isn't prepared (obviously) for multiple lines...I can't see what I am doing wrong.
One of my scripts helped you out? Please donate via Paypal
Re: How to execute a PowerShell script from XYplorer?
I'm simply pasting the two lines below into the "Try Script" dialog. It doesn't work for some reason. I know the HelloWorldFile.ps1 script works, and outputs text to a file. This seems like it should be straightforward.
$cmd = """powershell.exe"" -NoExit -File ""C:\Users\ra-bartonbf\PowerShell\HelloWorldFile.ps1""";
run $cmd;
$cmd = """powershell.exe"" -NoExit -File ""C:\Users\ra-bartonbf\PowerShell\HelloWorldFile.ps1""";
run $cmd;
Re: How to execute a PowerShell script from XYplorer?
Let me quote myself:
From the help file:but you didn't copy the indentation from within the code tags correctly
In a multi-line script all lines apart from the first line have to be indented by at least one space.
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 18
- Joined: 19 Nov 2017 00:06
Re: How to execute a PowerShell script from XYplorer?
For anyone reading this later here is what i did.
This will run any selected powershell scripts bypassing script signing.
USE AT YOUR OWN RISK
This was my first script so if there is anything to improve let me know.
I put an icon on my toolbar that runs it.
Code: Select all
foreach($token, <selitems |>, "|" ) {
$cmd = """powershell.exe"" -ExecutionPolicy Bypass -File ""$token""";
run $cmd;
}
USE AT YOUR OWN RISK
This was my first script so if there is anything to improve let me know.
I put an icon on my toolbar that runs it.