将每个csv项转换为字符串并将其添加到Hornbill简单列表中



下面的代码将stringValue添加到列表中:

# Define output stream type
[OutputType([object])]
# Define runbook input params
Param
(
# API Params
[string] $application = "com.hornbill.servicemanager",
[Parameter (Mandatory= $true)]
[string] $listName,
[Parameter (Mandatory= $true)]
[string] $itemValue = "",
[string] $defaultItemName,
[string] $itemNameTranslation
)
# Add XMLMC params
Add-HB-Param "application" $application $false
Add-HB-Param "listName" $listName $false
Add-HB-Param "itemValue" $itemValue $false
Add-HB-Param "defaultItemName" $defaultItemName $false
Add-HB-Param "itemNameTranslation" $itemNameTranslation $false
# Invoke XMLMC call, output returned as PSObject
$xmlmcOutput = Invoke-HB-XMLMC "data" "listAddItem"
$exceptionName = "" 
$exceptionSummary = ""

# Read output status
if($xmlmcOutput.params.itemValue -and $xmlmcOutput.params.itemValue -eq ""){
$itemValue = $name
$requestWarnings = $xmlmcOutput.params.warnings
}
if($xmlmcOutput.params.exceptionName -and $xmlmcOutput.params.exceptionName -ne ""){
$exceptionName = $xmlmcOutput.params.exceptionName
$exceptionSummary = $xmlmcOutput.params.exceptionDescription
}

# Build resultObject to write to output
$resultObject = New-Object PSObject -Property @{
Status = $xmlmcOutput.status
Error = $xmlmcOutput.error
ExceptionName = $exceptionName
ExceptionSummary = $exceptionSummary
itemValue = $itemValue
}
if($resultObject.Status -ne "ok" -or $exceptionName -ne ""){
Write-Error $resultObject
} else {
Write-Output $resultObject
}

:

$csv = Import-Csv applications.csv'
foreach($row in $csv)
{
$name = $row.Name
}

遍历csv文件中的列并返回2734项,但只返回"Total: 2734"被添加到列表。

如何将每个csv项转换为单个stringValue并将所有2734项添加到Hornbill简单列表中?

# Define output stream type
    [CmdletBinding()]
    # Define runbook input params
    Param
    (
        # API Params
        [string] $application = "com.hornbill.servicemanager",
        [string] $listName,
        [string] $itemNameTranslation
        )
   $csv = Import-Csv -Path 'All applications.csv'
   foreach($row in $csv)
   {
   $name = $row.Name
   Add-HB-Param "application" $application $false
   Add-HB-Param "listName" $listName $false
   Add-HB-Param "itemNameTranslation" $itemNameTranslation $false
   Add-HB-Param "itemValue" $name $false
   Add-HB-Param "defaultItemName" $name $false
   Invoke-HB-XMLMC "data" "listAddItem"
   }

相关内容

  • 没有找到相关文章

最新更新