# 利用cmd的bat呼叫powershell scripts,以curl為例 ###### tags: `程式設計` ## 使用情境 powershell的範例越來越多,但有些舊系統仍舊是使用bat定期觸發執行排程,要改成直接執行powershell得去改程式碼 在不更動程式碼只修改bat的情況下,就可以利用這個範例,讓bat可以執行powershell腳本 ## 使用方式 開啟記事本,將以下程式碼存入後,各自存成指定的檔名,然後用cmd執行execute.bat即可 ### powershellscript.ps1 ```=powershell curl -URi https://www.google.com Write-Host "Congratulations! PowerShell script executed successfully" ``` ### execute.bat ```=bat powershell -noexit "& ""D:\PowerShellTraining\PowerShellScript.ps1""" ``` ## 參考來源 ### 在PowerShell中使用curl(Invoke-WebRequest) https://www.cnblogs.com/woshimrf/p/5899629.html ### Invoking a PowerShell script from cmd.exe (or Start | Run) https://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up