如何从批处理文件运行 PowerShell 脚本 [英] How to run a PowerShell script from a batch file

查看:75
本文介绍了如何从批处理文件运行 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 Filesabc.exe"}

我制作了一个批处理脚本来运行这个 PowerShell 脚本

I have made a batch script to run this PowerShell script

@echo off
Powershell.exe set-executionpolicy remotesigned -File  C:UsersSEDesktopps.ps1
pause

但我收到此错误:

推荐答案

您需要 -ExecutionPolicy 参数:

Powershell.exe -executionpolicy remotesigned -File  C:UsersSEDesktopps.ps1

否则 PowerShell 会将参数视为要执行的一行,而 Set-ExecutionPolicy 一个 cmdlet,它没有 -File 参数.

Otherwise PowerShell considers the arguments a line to execute and while Set-ExecutionPolicy is a cmdlet, it has no -File parameter.

这篇关于如何从批处理文件运行 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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