如何运行一个批处理文件PowerShell脚本 [英] How to run a PowerShell script from a batch file
本文介绍了如何运行一个批处理文件PowerShell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在PowerShell中运行此脚本。我有救了以下脚本 ps.ps1
我的桌面上。
I am trying to run this script in PowerShell. I have saved the below script as ps.ps1
on my desktop.
$query = "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2"
Register-WMIEvent -Query $query -Action { invoke-item "C:\Program Files\abc.exe"}
我做了一个批处理脚本来运行这个PowerShell脚本
I have made a batch script to run this PowerShell script
@echo off
Powershell.exe set-executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1
pause
但我得到这个错误:
But I am getting this error:
推荐答案
您需要的 -ExecutionPolicy
参数:
Powershell.exe -executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1
否则PowerShell中考虑的参数一行来执行,虽然设置ExecutionPolicy
的是的cmdlet的,它没有 - 文件
参数。
Otherwise PowerShell considers the arguments a line to execute and while Set-ExecutionPolicy
is a cmdlet, it has no -File
parameter.
这篇关于如何运行一个批处理文件PowerShell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文