ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell Line Break at Comma

    IT Discussion
    powershell
    3
    5
    2.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by

      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.

      1 Reply Last reply Reply Quote 1
      • GregoryHallG
        GregoryHall
        last edited by

        Post the script as you have it now

        1 Reply Last reply Reply Quote 1
        • ?
          A Former User
          last edited by

          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 = "Autodesk@company.com"
          $MailMessage.To.add("guy@company.com")
          $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
          }
          
          1 Reply Last reply Reply Quote 0
          • ?
            A Former User
            last edited by A Former User

            Change it to, and it's working as expected

            $Body = $Lmtools -replace ",","`n"
            
            1 Reply Last reply Reply Quote 1
            • M
              Martin9700
              last edited by

              Should look into using Send-MailMessage for email. It's a lot easier to work with.

              1 Reply Last reply Reply Quote 2
              • 1 / 1
              • First post
                Last post