How to run powershell script that doesn't have ps1 extension
Asked Answered
F

1

10

I am using ops tool Rundeck that allows for execution of arbitrary scripts. I enter the script text in the web application widget and upon execution, Rundeck saves it to temporary file and calls interpreter. The problem is that the temporary file doesn't have ps1 extension and Powershell refuses to execute it.

Is there any way to set up Powershell to ignore extension ?

=== EDIT 2018 ===

Rundeck now has an option for this within a job definition.

Fastness answered 20/8, 2014 at 8:3 Comment(4)
Are you using Rundeck or Rundeck Pro? Rundeck Pro includes the capability to run PowerShell scripts.Palacios
I would say, this is not really a programming question, as you want to configure an application (PowerShell) to run differently. If you'd want to program an alternative interpreter (let's say a short C# tool taking your file as argument and executing it in PowerShell) it would fit better imho.Creamer
Maybe this could help you somehow vcloud-lab.com/entries/powershell/…Pillar
I found this thread which discusses the topic. Not fully convincing though.social.technet.microsoft.com/Forums/scriptcenter/en-US/…Chrysoberyl
O
5

I know I'm not strictly answering your questions regarding setting up PowerShell to ignore extensions, but here is one way of executing code from a textfile:

Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content .\file.txt)))

This reads the contents of file.txt and converts it into a scriptblock, before executing it using Invoke-Command.

Ocean answered 20/8, 2014 at 8:52 Comment(3)
I know that, but I can't use it, since I can only specify interpreter as a prefix, not insert the temporary file somewhere in between commands.Fastness
I would suggest to save the above line in a script file: powershellwrap.ps1, and designate this file as the interpreter executable for Rundeck.Chrysoberyl
This was not an option back then. Now it is, and hence the question is now outdated.Fastness

© 2022 - 2024 — McMap. All rights reserved.