Automate get-pendingrequest pki

Home Forums Scripting PowerShell Automate get-pendingrequest pki

This topic contains 4 replies, has 4 voices, and was last updated by  Anonymous 1 year, 7 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts

  • Ryzilla44
    Member
    #166987

    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 : pcid1
    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,$messagebody)

    Any ideas would be awesome


    JeremyW
    Moderator
    #271475

    Can you use Send-MailMessage? Something like this:
    $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[/CODE][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[/CODE]


    Anonymous
    #372042

    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.


    JeremyW
    Moderator
    #271477

    Variable names in powershell are case insensitive so that shouldn’t be an issue.


    Rems
    Moderator
    #228476
    Ryzilla44;n510419 wrote:
    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)}”
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.