如何在批处理文件中运行powershell命令
问题描述:
@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
当我另存为.bat文件并运行时,它将无法正常运行,否则当我手动输入时,它将在Powershell中正常运行.
when i save as .bat file and run it does not working otherwise it is working properly in powershell when i entering manually..
答
在其中包含PowerShell代码,
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/>')}"