Export-CEItems.ps1¶
The worker. Handles a single (TagType, TagName) across one or more workloads - calls Export-ContentExplorerData with pagination and writes one CSV per call.
You normally don't call this directly; the orchestrator dispatches it. But it's runnable on its own for one-off exports.
Synopsis¶
./Export-CEItems.ps1
-TagType <string>
-TagName <string>
[-Workloads <string[]>]
[-OutDir <string>]
[-PageSize <int>]
[-Force]
Parameters¶
| Name | Type | Default | Notes |
|---|---|---|---|
-TagType |
string |
required | One of Retention, SensitiveInformationType, Sensitivity, TrainableClassifier |
-TagName |
string |
required | Passed verbatim to Export-ContentExplorerData |
-Workloads |
string[] |
EXO,ODB,SPO,Teams |
Subset to query |
-OutDir |
string |
./output |
Where the per-tag CSV is written |
-PageSize |
int |
1000 |
1-10000, passed to Export-ContentExplorerData -PageSize |
-Force |
switch |
off | Overwrite existing per-tag CSV |
Examples¶
# One SIT, all four workloads
./Export-CEItems.ps1 -TagType SensitiveInformationType -TagName 'Credit Card Number'
# One SIT, just Exchange
./Export-CEItems.ps1 -TagType SensitiveInformationType -TagName 'Credit Card Number' -Workloads EXO
# Re-export an existing tag
./Export-CEItems.ps1 -TagType Sensitivity -TagName 'Confidential' -Force
Behaviour¶
- Skip-existing. If
output/items_<TagType>_<safe-name>.csvalready exists and-Forceis not set, log "skip (exists)" and return immediately. - Per-workload loop. For each workload in
-Workloads: a. First call:Export-ContentExplorerData -TagType $T -TagName $N -Workload $W -PageSize $P -ErrorAction Stop. b. WhileMorePagesAvailableisTrue, repeat with-PageCookie. c. For each returned record, prependTagType/TagName/Workloadcolumns. - Per-workload error handling. Errors are caught and warning-logged (
workload=<X> failed: <message>). The loop continues to the next workload. - All-workloads-errored detection. If every attempted workload threw, the worker re-throws so the orchestrator records the tag as
failrather than misleadingly reportingsucceeded with 0 rows. - Empty-result handling. If all workloads succeeded but returned 0 rows, write a header-only marker file so skip-existing on re-run leaves it alone.
- Write. All collected rows go into the per-tag CSV (UTF-8, no type info).
Edge cases handled¶
Export-ContentExplorerDatareturns null - happens when the cmdlet emitsWrite-Errorwithout throwing terminating (we've seen this with "A server side error has occurred"). The worker checks$null -eq $responsebefore indexing and surfaces a clearer message via the catch path.1..0array-range trap - whenRecordsReturnedis 0, naive code would index$response[1..0]which in PowerShell is[1, 0](a length-2 array of two indexes), not empty. The worker explicitly guards withif ($recordsReturned -gt 0).- Filename safe-name collisions - two tag names that normalize to the same safe-name (e.g.
Credit/Debit CardandCredit-Debit Cardboth →Credit_Debit_Card) would overwrite the same CSV. Rare in practice; not currently handled. The orchestrator's(TagType, TagName)dedupe doesn't catch this case.