強制實施 PowerShell 主機的最低版本

#requires -version 4

嘗試在較低版本中執行此指令碼後,你將看到此錯誤訊息

。\ script.ps1:指令碼’script.ps1’無法執行,因為它在 Windows PowerShell 5.0 版的第 1 行包含“#requires”語句。指令碼所需的版本與當前執行的 Windows PowerShell 版本 2.0 版本不匹配。