Routine CSV Export without DataPort
This post is in response to a question on the forum. The question asked how DataPort could be used to routinely export 3 fields from a record saved search into a CSV file and 2 fields from a location saved search into a separate CSV file. Here I'll show how to accomplish this with powershell.
First I wrote out the script...
Add-Type -Path "D:\Program Files\Hewlett Packard Enterprise\Content Manager\HP.HPTRIM.SDK.dll" $recordSearchSaveName = "My Saved Records" $userSavedSearchName = "My Saved Users" $recordCsv = "c:\temp\records.csv" $userCsv = "C:\temp\locations.csv" $db = New-Object HP.HPTRIM.SDK.Database $db.Connect() $records = New-Object HP.HPTRIM.SDK.TrimMainObjectsearch -ArgumentList $db, Record $records.SearchString = "saved:[$($recordSearchSaveName)]" $recordResults = New-Object System.Collections.ArrayList foreach ( $record in $records ) { $obj = new-object PSObject $obj | add-member -membertype NoteProperty -name "title" -value "$(([HP.HPTRIM.SDK.Record]$record).Title)" $obj | add-member -membertype NoteProperty -name "number" -value "$(([HP.HPTRIM.SDK.Record]$record).Number)" $obj | add-member -membertype NoteProperty -name "barcode" -value "$(([HP.HPTRIM.SDK.Record]$record).Barcode)" $recordResults.Add($obj) | Out-Null } $users = New-Object HP.HPTRIM.SDK.TrimMainObjectsearch -ArgumentList $db, Location $users.SearchString = "saved:[$($userSavedSearchName)]" $userResults = New-Object System.Collections.ArrayList foreach ( $user in $users ) { $obj = new-object PSObject $obj | add-member -membertype NoteProperty -name "title" -value "$(([HP.HPTRIM.SDK.Location]$user).FullFormattedName)" $obj | add-member -membertype NoteProperty -name "number" -value "$(([HP.HPTRIM.SDK.Location]$user).Barcode)" $userResults.Add($obj) | Out-Null } $recordResults | Export-Csv -Path $recordCsv -NoTypeInformation Write-Host "Exported Records to $recordCsv" $userResults | Export-Csv -Path $userCsv -NoTypeInformation Write-Host "Exported Locations to $userCsv"
Then I ran it...
And my results matched my expectations...
Now just schedule this powershell to run on your defined schedule!