OStack程序员社区-中国程序员成长平台

标题: How to run powershell command in batch file [打印本页]

作者: 菜鸟教程小白    时间: 2022-6-7 22:10
标题: How to run powershell command in batch file
@ECHO off

$BIOS= Get-WmiObject -computername "BAHRIATSG2-PC" -Namespace 
root/hp/instrumentedBIOS -Class HP_BIOSSettingInterface

$BIOS.SetBIOSSetting('Setup Password','<utf-16/>TheBIOSPassword','<utf-16/>')

pause

when i save as .bat file and run it does not working otherwise it is working properly in powershell when i entering manually..



Best Answer-推荐答案


Enclose your PowerShell code in,

powershell -Command "& {}"

Remember to separate all statements with ; and to enclose your " with a quoted string, i.e by using ""

powershell -Command "& {$BIOS= Get-WmiObject -computername ""BAHRIATSG2-PC\"" -Namespace root/hp/instrumentedBIOS -Class HP_BIOSSettingInterface; $BIOS.SetBIOSSetting('Setup Password','<utf-16/>TheBIOSPassword','<utf-16/>')}"





欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4