我有两个 API 端点来访问和检索用户信息并将数据写入 SQL 表。端点在 URL 中使用员工 ID,因此我遍历每个用户以获取他们的数据。端点 #2 包含用户的“自定义字段”。我正在尝试将两个端点的返回结合起来,并将它们写为 SQL 表中每个用户的单行。
它们将 PSCustomObject 作为哈希表返回。端点 #1:cat6 NoteProperty 字符串 cat6=NONE
端点 #2:CustomText94 NoteProperty System.Management.Automation.PSCustomObject CustomText94=@{description=; 价值=}
function Export-Feed {
Begin {
$serverInstance = ""
$database = ""
$tableName = ""
$employees = Get-Directory | Where-Object eestatus -eq A
}
Process {
$result = $employees | ForEach-Object -Parallel {
$params = @(
'firstname',
'middlename',
'lastname',
@{n='ADID';e={(Connect-Api -apiEndpoint "/api/v1/employee/$($_.eecode)/customfield").CustomText04.value}},
'hire_date',
'rehire_date',
'position_title',
'termination_date',
'work_email',
'employee_code',
'clocksequencenumber',
'department_code',
'department_description',
'employee_status',
'supervisor_primary',
'supervisor_primary_code',
'supervisor_secondary',
'supervisor_secondary_code',
'supervisor_tertiary',
'supervisor_tertiary_code',
'supervisor_quaternary',
'cat1',
'cat1desc',
'cat2',
'cat2desc',
'cat3',
'cat3desc',
'cat4',
'cat4desc',
'cat5',
'cat5desc',
'cat6',
'cat6desc',
'cat7',
'cat7desc',
'cat8',
'cat8desc',
'cat9',
'cat9desc'
)
Connect-Api -apiEndpoint "/api/v1/employee/$($_.eecode)" | Select-Object $params
}
}
End {
$result | Out-File c:\temp\test.txt
#Write-SqlTableData -DatabaseName $database -TableName $tableName -ServerInstance $serverInstance -SchemaName dbo -InputData $result -force
}
}