Powershell:如何从URI而不是本地磁盘获取JSON文件内容

时间:2022-05-26 00:33:11

Using Get-Content, I had developed my powershell script but later felt to move to cloud using storage repository used for templates.

使用Get-Content,我开发了我的PowerShell脚本,但后来觉得使用用于模板的存储库转移到云端。

$JsonContent = Get-Content $TFileUri | ConvertFrom-Json

Error:

Get-Content : Cannot find drive. A drive with the name 'https' does not exist.

获取内容:找不到驱动器。名称为“https”的驱动器不存在。

I attempted adding -Raw parameter which had helped me in other occasions before piping to ConvertFrom-Json but it gave me the following error:

我尝试添加-Raw参数,它在管道转换为ConvertFrom-Json之前在其他场合帮助了我,但它给了我以下错误:

$JsonContent = Get-Content $TFileUri -Raw | ConvertFrom-Json

Get-Content : A parameter cannot be found that matches parameter name 'Raw.

Get-Content:找不到与参数名称'Raw匹配的参数。

How to fetch a file from remote URI and workaround above challenge?

如何从远程URI获取文件并解决上面的挑战?

1 个解决方案

#1


1  

The following adaptation helped me move ahead ( not sure how standard the resolution is but sharing to be of some help )

以下调整帮助我继续前进(不确定分辨率是多么标准,但分享是有帮助的)

$JsonContent = Invoke-RestMethod -Uri $TFileUri

Note: I didnt find it necessary to convert JSON to object as well with above line.

注意:我没有发现有必要将JSON转换为对象以及上面的行。

#1


1  

The following adaptation helped me move ahead ( not sure how standard the resolution is but sharing to be of some help )

以下调整帮助我继续前进(不确定分辨率是多么标准,但分享是有帮助的)

$JsonContent = Invoke-RestMethod -Uri $TFileUri

Note: I didnt find it necessary to convert JSON to object as well with above line.

注意:我没有发现有必要将JSON转换为对象以及上面的行。