從 SSMS 執行 powershell

戴夫·帕

我正在嘗試按照某些 xp_cmdshell 代碼執行:

declare @url varchar(250) = 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=439d4b804bc8187953eb36d2a8c26a02'
declare @c varchar(1000) = N'powershell.exe -noprofile -executionpolicy bypass '
  + N'-command (Invoke-WebRequest -Uri '''+@url+'''-UseBasicParsing).content'
    print @c
exec xp_cmdshell @c

但這是我得到的錯誤:

The string is missing the terminator: '.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
 
'appid' is not recognized as an internal or external command,
operable program or batch file

當我嘗試在 powershell 中執行相同的操作時,我得到了預期的響應(見圖)

(Invoke-WebRequest -Uri 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=439d4b804bc8187953eb36d2a8c26a02'-UseBasicParsing).content

電源外殼

xp_cmdshell 的預期輸出應該是一個 json

克萊門特0

該錯誤消息暗示您的命令行是通過 執行的cmd.exe,其中&是一個元字符

要使用& 逐字-這是你的意圖-無論它的網址&是部分必須在封閉"..."cmd.exe只識別引號),或者你必須^-escape的&

declare @url varchar(250) = 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk^&appid=439d4b804bc8187953eb36d2a8c26a02'
-- ...

cmd.exe解析命令行,它識別^&作為逃脫 &被逐字使用和刪除^,轉義字符,傳遞參數上之前。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

從 Visual Studio 打開命令提示符而不是 Powershell 來執行 python

從文件內容讀取和執行操作

如何從解釋器執行 raku 腳本?

Iccube Rest API,如何從 C# 執行 ExecuteMdxScript?

如何從標準輸出執行命令?

PowerShell 開關在退出時再次執行

從終端直接執行 docker 可以正常工作,但從 .sh 腳本內部執行時則不行?

使用命令行參數從 Python 運行 C 可執行文件

如何在反應中從孩子執行父操作

從批處理文件執行 Rscript - 無法正確處理“Umlaute”(ä、ö、ü)

從javascript文件中的函數收集.href字符串而不執行它們

從 python flask 運行 c++ 可執行文件

雪花如何從執行方法返回查詢字符串

嘗試從 Python 執行 SQL 查詢時出現 KeyError

使用 fork() 和 exec() 從 C++ 執行 Python 代碼

如何從 bash 執行動態生成的 perl 腳本?

Kotlin 如何從父類強制執行子類

從上下文管理器中止執行 with 語句

在 React Javascript 中從狀態中獲取數據之前執行函數

如何從 Windows 批處理執行駐留在 Oracle APEX 上的 SQL 腳本

查詢從 C# 返回不同的結果,然後從 SSMS

從 Python 運行 Powershell 代碼 - 傳遞變量

PowerShell:從對象集合中選擇行,其中屬性 -lt X

從 R 運行 powershell 命令:表達式或語句中出現意外標記

Powershell 問題 - 如何從某個位置刪除行?

C# sqlite 如何從執行的 sqlite 命令行 .read 打印受影響的行

如何從一個簡單的java類調用javacc解析器並執行

找出執行輔助函數的控制器和方法(從輔助函數本身中)

無法直接從 vscode 調試或執行 venv 中的 python 代碼(沒有模塊命名...)