Need powershell script to send output (repadmin /replsum) in the mail body not as attachment.

Aditya 20 Reputation points
2023-04-17T06:15:17.4966667+00:00

Need powershell script to send output (repadmin /replsum) in the mail body not as attachment. i tried some script to send they were working but output data not came as they showing in CMD. all data come in single line.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,245 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,329 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 44,121 Reputation points
    2023-04-17T13:49:49.24+00:00
    
    Hello there,
    
    Give this a try, you can export it to CSV and import it back as objects:
    
    $result = dsquery computer domainroot -name * -limit 0 | foreach {
        repadmin /showattr $DCName $_ /atts:"WhenChanged,WhenCreated,OperatingSystem" /long
    } | Out-String
    
    $result.split([string[]]'DN:',[StringSplitOptions]::RemoveEmptyEntries) | Foreach-Object{
    
        $attr = $_.Split("`r`n",[StringSplitOptions]::RemoveEmptyEntries)
    
        New-Object -TypeName PSObject -Property @{
            DN = $attr[0].Trim()
            whenCreated = $attr[1].Trim() -replace '^1> whenCreated: '
            whenChanged = $attr[2].Trim() -replace '^1> whenChanged: '
            operatingSystem = $attr[3].Trim() -replace '^1> operatingSystem: '
        }
    
    }
    
    Hope this resolves your Query !!
    
    --If the reply is helpful, please Upvote and Accept it as an answer--
    
    0 comments No comments

  2. MotoX80 32,911 Reputation points
    2023-04-17T14:52:35.0333333+00:00

    If your email is formatted as ".IsBodyHtml = $true", then you just need to format the output from repladm to add the line breaks. On way would be to enclose the output in <pre> tags, or append <br> tags to each line.

    $out = repadmin /replsum
    $formattedout = "<pre>$out</pre>"    # one way
    $formattedout = $out -join "<br>"    # another way
    

  3. Aditya 20 Reputation points
    2023-04-24T04:51:04.2+00:00

    I have founded the script which is works for me. $repadminOutput = repadmin /replsum | Out-String $body = @" $repadminOutput "@

    0 comments No comments