Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

Help formatting Powershell output

Hello Powershell Experts,
I have an output formatting question.  I have a list of about 40 Active Directory objects that are either users or groups.  I have pieced together some code that will evaluate whether the object is a user or a group.  It will then display which groups the object is part of or display a message that states the object is not part of any groups.  The codes not pretty, but it gets the information I need.  However, it is not formatted the way I would like it.
Here is the code:
$POLObjects= "Poldev"
foreach ($Object in $POLObjects){
    $Data = Get-QADObject $Object | select name, type
    $DataGroupMembership = Get-QADGroup -ContainsMember $Data.name | Select Name
   If ($DataGroupMembership -eq $Null) {$groups = "This user is currently not in any AD groups."}
   Else {$groups = $DataGroupMembership}


Write-Host "The Active Directory object $($Data.name) is a $($data.type)."
Write-Host "$($Data.name) belongs to the following groups:"
Write-host "$($groups.name)"

} 

Open in new window

Here is the output displayed to the screen:
The Active Directory object poldev is a user.
Poldev belongs to the following groups:
Document Owners Document Managers Records Managers Domain Users

Open in new window

Here is what I would like the displayed output to look like:

The Active Directory object poldev is a user.
Poldev belongs to the following groups:
Document Owners
Document Managers
Records Managers
Domain Users

My formatting questions are:
1.       How do I get the groups to be presented in a list?
2.      Can I have the list italicized?
3.      Could I get this sent to a text file as opposed to the screen?

Thanks in advanced for your help.
Nick
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial