Powershell Line Break at Comma
-
I'm making a power shell script and using a batch file command from a utility to set as a string. I need to take that string and make line breaks after every comma how do I do that? It's for an automated email.
-
Post the script as you have it now
-
This is my current one, It polls LMTools to check for autodesk licensing usage, and only sends if all are used. It writes a text file so it doesn't send again until the condition clears and started again. (it runs via a scheduled task).
#This Script Queries LMTools and Sends and Email with usage when full #Written by Jason $Email = cd "C:\Program Files\Autodesk Network License Manager\" $Lmtools = .\lmutil.exe lmstat -f LICESNENAME $Body = $Lmtools -replace ',',"`n" If (($Lmtools -like '*Total of 200 licenses in use*') -and (!(Test-Path -Path C:\Scripts\Autodesk.txt -PathType Leaf))){$MailBody= $Body $MailSubject= "Autodesk License Full" $SmtpClient = New-Object system.net.mail.smtpClient $SmtpClient.host = "SMTPSERVER" $MailMessage = New-Object system.net.mail.mailmessage $MailMessage.from = "[email protected]" $MailMessage.To.add("[email protected]") $MailMessage.IsBodyHtml = 0 $MailMessage.Subject = $MailSubject $MailMessage.Body = $MailBody $SmtpClient.Send($MailMessage) New-Item 'C:\Scripts\Autodesk.txt' -type file -force -value 1 } ElseIf (!($Lmtools -like '*Total of 200 licenses in use*')) {Remove-Item 'C:\Scripts\Autodesk.txt' } Else {Exit }
-
Change it to, and it's working as expected
$Body = $Lmtools -replace ",","`n"
-
Should look into using Send-MailMessage for email. It's a lot easier to work with.