Add array collections to cell in CSV

BlackCat 81 Reputation points

I am using Get-ADDomain to have list of child domain
$DomainInfo = Get-ADDomain $env:USERDNSDOMAIN
$ChildDomains = $DomainInfo.ChildDomains

This will give me all child domains in format "". I want to export result to CSV with headers and all child domains will add to column header "CHild Domains".

This is my code to create CSV with headers
$obj = [pscustomobject]@{

FQDN = $

ForestMode = $ForestInfo.Forestmode

SchemaMaster  = $ForestInfo.SchemaMaster

DomaininForest = $ForestInfo.Domains.Count

   ChildDomains = "$ChildDomains"

   ChildCount = $ChildDomains.Count

This is K for me but all child domains are showed as one line "" at column "Child Domains". I want to format it as

Child Domains

How can I archive this?


Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,405 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,111 Reputation points

    The short answer is that you can't.

    A CSV has no concept of formatting.

    You can get Excel to do it though. To put multiple values in the same cell you need to separate them, so something like this may work for you by changing line #9 in you example:

    ChildDomains = $ChildDomains -join "`n"

    Import the result into Excel and get the cell height big enough to show "x" number of values.

0 additional answers

Sort by: Most helpful