troubleshooting Question

Powershell assistance needed breaking up results being read as a string and creating attachment of results

Avatar of Mase2k
Mase2kFlag for United States of America asked on
Scripting LanguagesPowershellWindows Server 2012
13 Comments1 Solution223 ViewsLast Modified:
Trying to write a script to output a list of users who currently have a specific file open for use. I have the results showing proper when executed in powershell but when I read them into a string to send out in an email they all come out on a single line. I need to figure out how to get the usernames to show on multiple lines and not all in one line. I also need to figure out how to export the results as a file and attach to the same email. Any help you can offer would be great!

Two powershells:

Get-SmbOpenFile | Where-Object -Property ShareRelativePath -Match "S2K" | Where-Object -Property ShareRelativePath -NotMatch "IMAGES" | Sort-Object ClientUsername | Select-Object -ExpandProperty ClientUsername

$body = C:\Results.ps1
Send-MailMessage -To (To address) -from (From address) -subject "Currently logged in users for $(Get-Date)" -Body "The below list of users are using the file.`n`nAttached is a more user friendly version.`n`n$body" -SmtpServer (SMTP Server)

Currently outputs like this:

Desiring it output like this:
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros