[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with some formating in a here-string in Powershell

Posted on 2015-01-14
3
Medium Priority
?
98 Views
Last Modified: 2015-01-14
Hello Powershell Experts,

I want to do a proof of concept using Powershell to generate a group membership audit report.  We have a file that has a list of authorized users for the test group.  I then want to compare the list of authorized user to the users actually in the group in Active Directory.  This is easy enough.  I’ve written the following to achieve this goal:

$TargetGroup = "NickTestGroup2"

$AuthorizedGroupMembers = Get-Content -Path C:\PowershellResources\Group2.txt

$GroupMembersInAD = Get-ADGroupMember -Identity $TargetGroup | ForEach-Object {$_.name}

$UnauthorizedGroupMembers = Compare-Object $GroupMembersInAD $AuthorizedGroupMembers -IncludeEqual | Where {$_.sideindicator -eq "<="} | ForEach-Object {$_.Inputobject}

$EmailBody = @"
The following is a list of unauthorized users in the '$TargetGroup':
$UnauthorizedGroupMembers
"@

This almost gives me what I want.  The value of the $EmailBody variable as it is now is:

The following is a list of unauthorized users in the ‘Test Group’:
User1 User2 User3

Ideally, I would like the output to look like:

The following is a list of unauthorized users in the ‘Test Group’:
User1
User2
User3


My question to all of you is:
How can I get my output to is how can I get the content of the $EmailBody variable to list the users on different lines as detailed above?
0
Comment
Question by:ndalmolin_13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 40549288
Try this:
$EmailBody = @"
The following is a list of unauthorized users in the '$TargetGroup':
$($UnauthorizedGroupMembers -join "`r`n")
"@

Open in new window

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40549293
You change the default string separator $OFS (which is space by default), or join the strings yourself using a different separator.
$EmailBody = @"
The following is a list of unauthorized users in the '$TargetGroup':
$($UnauthorizedGroupMembers -join "`r`n")
"@ 

Open in new window

0
 
LVL 1

Author Closing Comment

by:ndalmolin_13
ID: 40549902
That worked great.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question