【发布时间】:2020-01-02 02:12:03
【问题描述】:
我正在使用 Layer2 Cloud Connector 作为数据集成服务。该软件有一个基于本地的 REST API,可由 PowerShell 脚本调用。我正在尝试创建一个脚本,该脚本将使用 Invoke-RestMethod 发布与服务的新连接,如documentation 所示。我的 POST 调用成功,但我的帖子中的数组作为 System.Object[] 发送。
有人可以帮我理解为什么会这样吗?
当我运行下面的代码时,调用成功地创建了连接,但是作为数组传递的任何内容都显示为 System.Object[]。
$body = @{
name = "Sites Test"
consecutiveErrors = 0
initialOverwrite = $True
direction = "LeftToRight"
schedule = @{
enabled = $False
interval = 10
start = "2019-02-14T06:19:45.3892419-07:00"
}
leftEntity = @{
name = "left"
providerInvariantName = "Layer2.LaCuaba.JSON"
connectionString = "Uri=https://example.url;"
selectStatement = "SELECT * from JSONData"
primaryKey = "code"
encryptions = @()
deletionProtectionThreshhold = 30
}
rightEntity = @{
name = "right"
providerInvariantName = "Layer2.SharePoint.Provider"
connectionString = "Url=https://example.url;"
selectStatement = "SELECT * from JSONData"
primaryKey = ""
operation = @(
"Read",
"Delete",
"Insert",
"Update"
)
encryptions = ((
"ConnectionString"
) -join ",")
deletionProtectionThreshhold = 30
}
mapping = @{
auto = $False
entries = @(
@{
left = "code"
right = "Title"
},
@{
left = "description"
right = "Description"
},
@{
left = "alternateId"
right = "RandomNumber"
}
)
}
conflictResolution = @{
name = "FailAndAbort"
entity = ""
}
}
$jsonBody = $body | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:[port]/v1/connections" -Method Post -Body $jsonBody -ContentType "application/json"
根据我读过的所有其他 Invoke-RestMethod 问题,'-ContentType "application/json"' 应该可以解决我遇到的问题,但输出仍然显示 System.Object[]。以下是输出示例:
name : Sites Test
consecutiveErrors : 0
initialOverwrite : True
direction : LeftToRight
schedule : @{enabled=False; interval=10; start=2019-02-14T06:19:45.3892419-07:00}
leftEntity : @{name=left; providerInvariantName=Layer2.LaCuaba.JSON; connectionString=Uri=https://example.url;;
selectStatement=SELECT * from JSONData; primaryKey=code; replicationKey=; generateId=False; operations=System.Object[];
encryptions=System.Object[]; dynamicColumns=System.Object[]; deletionProtectionThreshold=0}
rightEntity : @{name=right; providerInvariantName=Layer2.SharePoint.Provider;
connectionString=Url=https://example.url;
selectStatement=SELECT * from JSONData; primaryKey=; replicationKey=; generateId=False; operations=System.Object[]; encryptions=System.Object[];
dynamicColumns=System.Object[]; deletionProtectionThreshold=0}
mapping : @{auto=False; entries=System.Object[]}
conflictResolution : @{name=FailAndAbort; entity=}
error :
任何帮助将不胜感激!
【问题讨论】:
标签: arrays json powershell scripting