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.
Run Your PowerShell Scripts. After configuring the execution policy, you can run PowerShell scripts. To run a script, open a PowerShell window, type the script's name (with or without the . ps1 extension) followed by the script's parameters (if any), and press Enter.
ps1 files are interpreted by PowerShell, the Command Prompt (CMD) cannot work with PowerShell scripts directly. If you would like to run a PowerShell script in CMD, you'll need to execute it by calling the PowerShell process with the -File parameter, as shown below: PowerShell -File C:\TEMP\MyNotepadScript. ps1.
By default a file of type script ( . ps1 ) is created, but it can be saved with a new name and extension.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With