设置自动执行的PowerShell脚本 [英] Set up PowerShell Script for Automatic Execution

查看:733
本文介绍了设置自动执行的PowerShell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几行PowerShell代码,我想用作自动脚本。我希望它能够工作的方式是能够使用以下选项之一调用它:

I have a few lines of PowerShell code that I would like to use as an automated script. The way I would like it to be able to work is to be able to call it using one of the following options:


  1. 一个命令行打开PowerShell,执行脚本并关闭PowerShell(这将用于全局构建例程)

  2. 一个文件,我可以双击运行上述(我将使用此方法当我手动测试我的构建过程的组件)



我已经在线通过PowerShell文档,虽然我可以找到很多脚本,我一直无法找到如何做我需要的指示。感谢您的帮助。

I have been going through PowerShell documentation online, and although I can find lots of scripts, I have been unable to find instructions on how to do what I need. Thanks for the help.

推荐答案

将脚本保存为.ps1文件,并使用powershell.exe启动, / p>

Save your script as a .ps1 file and launch it using powershell.exe, like this:

powershell.exe .\foo.ps1

确保指定脚本的完整路径,并确保已将执行策略级别设置为至少为RemoteSigned,以便可以运行未签名的本地脚本。

Make sure you specify the full path to the script, and make sure you have set your execution policy level to at least "RemoteSigned" so that unsigned local scripts can be run.

这篇关于设置自动执行的PowerShell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆