Python中调用PowerShell、远程执行bat文件实例
python调用本地powershell方法
1、现在准备一个简陋的powershell脚本,功能是测试一个IP列表哪些可以ping通:
function test_ping($iplist)
{
foreach ($myip in $iplist)
{
$strQuery = "select * from win32_pingstatus where address = '$myip'"
# 利用 Get-WmiObject 送出 ping 的查詢
$wmi = Get-WmiObject -query $strQuery
if ($wmi.statuscode -eq 0)
{
return "Pinging`t$myip...`tsuccessful"
}
else
{
return "Pinging`t$myip...`tErrorCode:" + $wmi.statuscode
}
}
}
test_ping args[0]
以上是 Python中调用PowerShell、远程执行bat文件实例 的全部内容, 来源链接: utcz.com/z/321087.html