【发布时间】:2021-02-28 17:06:27
【问题描述】:
我是 Powershell 的新手,我正在尝试从 Teams 中提取数据(使用 Graph API)我已成功将所需数据导出到 SQL 表中(使用 Invoke-Sqlcmd 函数)
提取通话中涉及的用户时,我得到了 CallID,但参与者值放在单个字段中
CallID Participants
CallGUID-xxxx-xxxx-xxxx-xxxxxxxxxx John Smith Mary Brown Billy Dee Williams
我需要像下面这样格式化它
CallID Participants
CallGUID-xxxx-xxxx-xxxx-xxxxxxxxxx John Smith
CallGUID-xxxx-xxxx-xxxx-xxxxxxxxxx Mary Brown
CallGUID-xxxx-xxxx-xxxx-xxxxxxxxxx Billy Dee Williams
我使用的代码如下。
$clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$clientSecret = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$tenantName = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$tenantName = "xxxxxxxx.onmicrosoft.com"
$resource = "https://graph.microsoft.com/"
$tokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $clientId
Client_Secret = $clientSecret
}
$URL = "https://graph.microsoft.com/v1.0/communications/callRecords/CallGUID-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $tokenBody
$response = Invoke-RestMethod -Headers @{Authorization = "Bearer $($tokenResponse.access_token)"} -Uri $URL
$CallDetailsID = $response.id
$CallDetailsStart = $response.startDateTime
$CallDetailsEnd = $response.endDateTime
$CallDetailsParticipants = $response.Participants.user.displayname
Invoke-Sqlcmd -Query "INSERT INTO [Alpha].[dbo].[Table] (CallID, Participants) SELECT '$CallGUID', $CallDetailsParticipants)" -ServerInstance "Server\Instance"
有人能帮忙指出我做错了什么吗?
【问题讨论】:
标签: sql sql-server powershell import