![](/img/trans.png)
[英]Unable to load .ps1 powershell script from Powershell command (console)
[英]Windows command console to run powershell script(ps1)
我想從批處理文件中運行 run.ps1。 我需要在網站上下載一個只需要 http 請求的可執行文件。
my.ps1 代碼適用於 Windows Powershell ISE(未提升),但不是從我的批處理文件運行時。
我的 batch and.ps1 文件如下,誰能幫幫我?
這是批處理文件
echo test
powershell -noexit -file C:\Users\username\Desktop\tyty.ps1
pause
這是 ps.1
$userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer
$downloadUrl = ((Invoke-WebRequest –Uri "http://tax.nat.gov.tw/info_BLR_download.html?id=2").Links | Where-Object {$_.href -like “*BLR_*I.exe” -and $_.href -notlike “*BLRATH*” } | Select-Object -ExpandProperty href)
Invoke-WebRequest -Uri $downloadUrl -OutFile "C:\Temp\BLR.exe" -UserAgent $userAgent
錯誤
[Microsoft.PowerShell.Commands.PSUserAgent]。 C:\Users\username\Desktop\tyty.ps1:1 字元:14
+ $userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power...nds.PSUserAgent:TypeName) [],RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
要使類型可用,如果 PowerShell 沒有自動加載它,只需使用Import-Module
或Add-Type
手動添加相應的模塊或程序集。 在您的情況下,您必須加載一個可以從文檔( Microsoft.PowerShell.Commands.PSUserAgent
)派生的程序集:
Add-Type -AssemblyName Microsoft.PowerShell.Commands.Utility
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.