简体   繁体   English

如何运行没有ps1扩展名的powershell脚本

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

I am using ops tool Rundeck that allows for execution of arbitrary scripts. 我正在使用ops工具Rundeck,它允许执行任意脚本。 I enter the script text in the web application widget and upon execution, Rundeck saves it to temporary file and calls interpreter. 我在Web应用程序窗口小部件中输入脚本文本,并在执行时,Rundeck将其保存到临时文件并调用解释器。 The problem is that the temporary file doesn't have ps1 extension and Powershell refuses to execute it. 问题是临时文件没有ps1扩展名,Powershell拒绝执行它。

Is there any way to set up Powershell to ignore extension ? 有没有办法设置Powershell来忽略扩展?

=== EDIT 2018 === === 2018年编辑===

Rundeck now has an option for this within a job definition. Rundeck现在在作业定义中有一个选项。

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: 我知道我并没有严格回答有关设置PowerShell以忽略扩展的问题,但这是从文本文件执行代码的一种方法:

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. 这将读取file.txt的内容并将其转换为scriptblock,然后使用Invoke-Command执行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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