PowerShell - 将数据行列类型设置为自定义对象

PowerShell - Setting a Data Row column type to a custom object

我认为自己对 PowerShell 中的脚本编写相当陌生,目前我在将 API 请求的 return 值分配给数据行时遇到问题。

returned 值似乎是自定义对象:<APITenant>.FRSHEATServiceReqTemplateParam 如果我尝试将其分配给数据 table,它只会显示对象名称而不是值例如

Name                                 Params                                   
----                                 ------                                   
Access to Mailbox/Distribution Group OscarStg.FRSHEATServiceReqTemplateParam[]
strSubscriptionRecId : 0221877CF3474492B8ACD9F7C0D94E4A
strDateSubscribed    : 10/6/2017 8:09:58 AM
strOrgUnitId         : 37393D7C9B554ACEB1F2F2505BA1FF6D
strName              : Access to Mailbox/Distribution Group
strItem              : 
strDescription       : Request for access to be added or removed from a 
                       mailbox/group.
strServiceName       : Email Messaging Service
strRecId             : 21BB52854D524958A5C9F9E0DCAB60CB
lstParameters        : {eacc_dpmnt, eacc_req, eacc_reqEmail, eacc_item...}

我可以将实际值赋给数据吗table?

编辑:

$cboTmpl.Add_SelectedIndexChanged({
    $tmplRecId = $cboTmpl.SelectedItem["RecId"]
    $index = $dTblTmpl.RecId.IndexOf($cboTmpl.SelectedValue)
    If($dTblTmpl.Rows[$index].SubId.GetTypeCode() -eq 'DBNull'){
        $tmpSubName = $dTblTmpl.Rows[$index].Name.Replace("&", "&amp;")
        $dTblTmpl.Rows[$index].SubId = ($Oscar.GetSubscriptionId($connect.sessionKey, `
        $txtTenant.Text, $tmpSubName)).subscriptionId
    }
    If($dTblTmpl.Rows[$index].Params.GetTypeCode() -eq 'DBNull'){
        $currParams = ($Oscar.GetPackageData($connect.sessionKey, $txtTenant.Text, $dTblTmpl.Rows[$index].SubId)).srSubscription.lstParameters
        $dTblTmpl.Rows[$index].Params = $currParams
    }
})

最后一个 if 块调用该方法并将其分配给数据 table。我尝试使用 -ExpandProperty 但它同样将字符串 'System.Object[]' 分配为值。

是否需要显式定义列对象?

成功了 - 我必须明确地将列定义为对象的基本类型。在这种情况下,[System.Array].

New-Variable -Name "$('col' + $Header)" -Value (New-Object `
        System.Data.DataColumn $Header,([System.Array])) -Force}

现在 returns 正确的值。

$dTblTmpl.Rows[2] | select Name, Params

Name           Params
----           ------
[TEST] Request {chk, qty}