我是靠谱客的博主 虚心外套,这篇文章主要介绍通过bat运行powershell 脚本通过bat运行powershell 脚本,现在分享给大家,希望可以做个参考。

通过bat运行powershell 脚本

个人记录备份
powershell 的脚本一般为ps1后缀,直接双击是无法运行,一般是结合bat文件来配合运行。

# %temp%test.ps1 为实际脚本目录
powershell -executionpolicy remotesigned -file "%temp%test.ps1"

这样实际在用的时候,还有个问题就是,需要把2个文件都拷贝过去,这样才能使用。
针对这个问题,可以通过在bat里写好脚本,之后通过bat生成ps1脚本,并运行
实际代码


echo $computer="%cname%" > "%temp%test.ps1"
for /f "delims=:" %%i in ('findstr /n "^:JoinDomain$" "%~f0"') do (
	more +%%i "%~f0" >> "%temp%test.ps1"
)
powershell -executionpolicy remotesigned -file "%temp%test.ps1"
pause
:JoinDomain
::这块直接填写对应的ps1脚本内容即可。

最后

以上就是虚心外套最近收集整理的关于通过bat运行powershell 脚本通过bat运行powershell 脚本的全部内容,更多相关通过bat运行powershell内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部