在批处理文件中执行powershell脚本 [英] Execute powershell script inside batch file

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

问题描述

可能的重复:
如何从批处理文件执行powershell命令?

我想在不创建 ps1 文件的情况下从批处理文件中执行以下 powershell 语句

I want to execute the below powershell statement from a batch file with out creating a ps1 file

if([System.Diagnostics.EventLog]::SourceExists("dfgdjg") -eq $false){[System.Diagnostics.EventLog]::CreateEventSource("dfgdjg","dfgdjgLogs");}
else{write("Event Log already exists");}

可以吗?

推荐答案

一般你可以这样做:

 @powershell -command "yourpowershellcommand"

您可以直接使用powershell.exe,但我建议您使用上述形式的@powershell

You can use powershell.exe directly, but I would recomment you to use the above form of @powershell

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

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