Powershell 使用power shell纠正SSRS API部署的put方法以设置shareddataset

Powershell 使用power shell纠正SSRS API部署的put方法以设置shareddataset,powershell,Powershell,我想使用PowerShell为使用SSRS API的报表设置shareddataset 我已经尝试使用PowerShell成功地使用SSRS API获取shareddataset。但未能使用put方法 使用get方法成功: $Cred = Get-Credential $Url = "http://localhost/Reports/api/v2.0/DataSets" ` `$Body = @{ Path ="/Shared_data_sets/P_Calculate_date_Defaul

我想使用PowerShell为使用SSRS API的报表设置shareddataset

我已经尝试使用PowerShell成功地使用SSRS API获取shareddataset。但未能使用put方法

使用get方法成功:

$Cred = Get-Credential

$Url = "http://localhost/Reports/api/v2.0/DataSets"
`
`$Body = @{
Path ="/Shared_data_sets/P_Calculate_date_Default_key";
output_mode = "csv";
earliest_time = "-2d@d";
latest_time = "-1d@d";
}

Invoke-RestMethod -Method 'GET' -Uri $url -Credential $Cred -Body $body -OutFile output.csv
$Cred = Get-Credential

$Url = "http://localhost/Reports/api/v2.0/Reports(23a6af79-9de3-49cb-b66b-625d3ff3909b)/SharedDataSets"

$Body = @{
Id = "935be257-5a65-4c0d-b372-d5a6a188daf6";
Name = "P_Calculate_Date_Default_Key";
Path = "/Shared_data_sets/P_Calculate_date_Default_key";
Type = "DataSet" ;
}

Invoke-RestMethod -Uri $Url -Credential $Cred -Body $body -Method 'PUT'
使用put方法失败:

$Cred = Get-Credential

$Url = "http://localhost/Reports/api/v2.0/DataSets"
`
`$Body = @{
Path ="/Shared_data_sets/P_Calculate_date_Default_key";
output_mode = "csv";
earliest_time = "-2d@d";
latest_time = "-1d@d";
}

Invoke-RestMethod -Method 'GET' -Uri $url -Credential $Cred -Body $body -OutFile output.csv
$Cred = Get-Credential

$Url = "http://localhost/Reports/api/v2.0/Reports(23a6af79-9de3-49cb-b66b-625d3ff3909b)/SharedDataSets"

$Body = @{
Id = "935be257-5a65-4c0d-b372-d5a6a188daf6";
Name = "P_Calculate_Date_Default_Key";
Path = "/Shared_data_sets/P_Calculate_date_Default_key";
Type = "DataSet" ;
}

Invoke-RestMethod -Uri $Url -Credential $Cred -Body $body -Method 'PUT'
返回的错误为

远程服务器返回错误:(400)请求错误

详细错误:

调用RestMethod:远程服务器返回错误:(400)请求错误。第12行字符:1+调用RestMethod-Uri$Url-Credential$Cred-Body$Body-Method'PU…+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[Invoke RestMethod],WebException+FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeSetMethodCommand

我希望put方法能起作用。我认为我使用的方法与get方法相同,但它仍然失败

我尝试了另一种方法,但还是失败了:

$Cred = Get-Credential
$Url = "http://localhost/Reports/api/v2.0/Reports(23a6af79-9de3-49cb-b66b-625d3ff3909b)/SharedDataSets"
$Body = @{

   Id = "935be257-5a65-4c0d-b372-d5a6a188daf6"
  Name = "P_Calculate_Date_Default_Key"
  Path = "/Shared_data_sets/P_Calculate_date_Default_key"
  Type = "DataSet"

}| ConvertTo-Json

Invoke-RestMethod -Uri $Url -Credential $Cred -Body $body -Method PUT -ContentType "application/json" | Out-Null
只是想让你知道,对于put方法,我已经在postman上进行了测试,它是有效的。所以我猜目前这只是因为powershell端的一些逻辑不一致

在《邮递员》中,我将链接放在:

正文如下:

[
  {
      "Id": "935be257-5a65-4c0d-b372-d5a6a188daf6",
      "Name": "P_Calculate_Date_Default_Key",
      "Path": "/Shared_data_sets/P_Calculate_date_Default_key",
      "Type": "DataSet"
  }
]
我尝试了您的建议,结果如下所示,我已将其添加到以下所有内容: PS C:\Users\dkx42a8adm>$Cred=Get-Credential $Url=“” $Body=@{

   Id = "935be257-5a65-4c0d-b372-d5a6a188daf6"
  Name = "P_Calculate_Date_Default_Key"
  Path = "/Shared_data_sets/P_Calculate_date_Default_key"
  Type = "DataSet"

}| ConvertTo-Json

Write-Output $Body

Invoke-RestMethod -Uri $Url -Credential $Cred -Body $body -Method PUT -ContentType "application/json" 

$error[0]|format-list -force
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
{
"Path":  "/Shared_data_sets/P_Calculate_date_Default_key",
"Name":  "P_Calculate_Date_Default_Key",
"Id":  "935be257-5a65-4c0d-b372-d5a6a188daf6",
"Type":  "DataSet"
}
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:14 char:1
+ Invoke-RestMethod -Uri $Url -Credential $Cred -Body $body -Method PUT     ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation:     (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
异常:System.Net.WebException:远程服务器返回错误:(400)请求错误。 位于Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest请求) 在Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()中 TargetObject:System.Net.HttpWebRequest CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[调用RestMethod],WebException FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand 错误详细信息: 调用信息:System.Management.Automation.InvocationInfo ScriptStackTrace:at,:第14行 PipelineIterationInfo:{}
PSMessageDetails:

抱歉,请忽略“`”。我编辑此问题时似乎有错误。请扩展到“失败”。您是否收到错误,或者它只是没有做任何事情?亲爱的Nick,错误如下所示:调用RestMethod:远程服务器返回错误:(400)请求错误。第12行字符:1+调用RestMethod-Uri$Url-凭证$Cred-Body$Body-Method'PU…+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~类别信息:无效操作:(System.Net.Net.HttpWebRequest:httpRequest调用RestMethod,WebException+FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokerestMethodCommand,请编辑原始问题并将其放入其中。在这里的示例中,主体的定义不同。请仔细将您的
$body
与示例
$payload
进行比较。例如,示例中有一个
\124; ConvertTo Json
,而你的却没有