Announcement

Collapse
No announcement yet.

Automate get-pendingrequest pki

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automate get-pendingrequest pki

    Hi Guys

    I am having some issues trying to get a script working that will check my CA for any pending requests, i'm using a pki module that can do this for me.

    Get-PendingRequest CA1,CA2

    Will show the following

    RequestID : 1262
    Request.RequesterName : pc\id1
    Request.SubmittedWhen : 28/04/2017 4:48:37 AM
    Request.CommonName : abc.google.com
    CertificateTemplate : Web SSL
    RowId : 1262
    ConfigString : CA1
    Table : Request

    Now if i try and get that to email me when script is run i get a empty email.

    Send-Email.ps1 -To "[email protected]" -Subject "Pending Rewquest" -Body (Get-PendingRequest CA1,CA2)

    The send-email is;
    param(
    [string]$to,
    [string]$subject,
    [string]$body
    )

    $smtpServer = "[email protected]"
    $smtpFrom = "[email protected]"
    $smtpTo = $to
    $messageSubject = $subject
    $messageBody = $body

    $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($smtpFrom,$smtpTo,$messagesubject,$mess agebody)

    Any ideas would be awesome

  • #2
    Can you use Send-MailMessage? Something like this:
    Code:
    $smtpServer = "[email protected]"
    $smtpFrom = "[email protected]"
    $body = Get-PendingRequest CA1,CA2 | Out-String
    
    Send-MailMessage -To "[email protected]" -Subject "Pending Rewquest" -Body $body -From $smtpFrom -SmtpServer $smtpServer
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Check what you submitted to us, you may simply have a text case issue. In your last code statement, you call out '$messagesubject' and '$messagebody', but in the previous statements they appeared as '$messageSubject' and '$messageBody'. Since the variable names don't match, the values as defined aren't being called. I've had that happen a few times.
      *RicklesP*
      MSCA (2003/XP), Security+, CCNA

      ** Remember: credit where credit is due, and reputation points as appropriate **

      Comment


      • #4
        Variable names in powershell are case insensitive so that shouldn't be an issue.
        Regards,
        Jeremy

        Network Consultant/Engineer
        Baltimore - Washington area and beyond
        www.gma-cpa.com

        Comment


        • #5
          Originally posted by Ryzilla44 View Post
          Hi Guys

          I am having some issues trying to get a script working that will check my CA for any pending requests, i'm using a pki module that can do this for me.

          Get-PendingRequest CA1,CA2

          Now if i try and get that to email me when script is run i get a empty email.

          Send-Email.ps1 -To "[email protected]" -Subject "Pending Rewquest" -Body (Get-PendingRequest CA1,CA2)

          Any ideas would be awesome
          The answer provided by JeremyW should work >> $body = Get-PendingRequest CA1,CA2 | Out-String
          The pipeline operator (|) sends the content to Out-String, this returns the output as a string for the -Body argument

          You can also,
          Code:
          Send-Email.ps1 -To "[email protected]" -Subject "Pending Rewquest" -Body (Get-PendingRequest CA1,CA2 | out-string)
          or,
          Code:
          powershell.exe -executionpolicy bypass -File Send-Email.ps1 -To "[email protected]" -Subject "Pending Rewquest" -Body (Get-PendingRequest CA1,CA2 | out-string)

          The command lines above should of course be launched from a powershell prompt.

          If the default command-line interpreter of Windows (cmd .exe) is used then the command line in total should be like,
          Code:
          powershell.exe -executionpolicy bypass "& {powershell.exe -File Send-Email.ps1 -To "[email protected]" -Subject "Pending Rewquest" -Body (Get-PendingRequest CA1,CA2 | out-string)}"
          Last edited by Rems; 3rd May 2017, 23:01.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment

          Working...
          X