简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM