Invoke Generate Self Signed Certificate

Welcome Forums General PowerShell Q&A Invoke Generate Self Signed Certificate

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 10 months ago.

  • Author
    Posts
  • #26857

    Participant
    Points: 0
    Rank: Member

    Good Morning,

    I am very new to Powershell and scripting in general. I thought I would try to make a small script to invoke the New-SelfsignedCertificate Cmdlet on a remote server or servers. (The makecert tool gets a little tedious when you have to use it often.) Here is my script.

    ————————————————————————————————————————–

    Param (
        [Parameter(Mandatory=$True)]
        [string]$computername,
        [Parameter(Mandatory=$True)]
        [string]$CertStoreLocation,
        [Parameter(Mandatory=$True)]
        [string]$dnsname
        
        )
    
    
    $Params = @{
        "CertStoreLocation"=$CertStoreLocation
        "DNSname"=$dnsname
        
    }
    
    Invoke-command $computername New-SelfSignedCertificate @Params

    ————————————————————————————————————-
    So when I run the script locally with the invoke-command cmdlet commented out, I can give the certstorelocation parameter "cert:\localmachine\my" and it works beautifully.

    When I try to invoke on a remote computer I get.

    —————————————————————————————————————-
    Invoke-Command : A parameter cannot be found that matches parameter name 'CertStoreLocation'.
    At C:\Users\jason.garner\Google Drive\Scripts\GenerateSSL.ps1:18 char:56
    + Invoke-command $computername New-SelfSignedCertificate @Params
    + ~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingExcepti
    on
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeCom
    mandCommand
    ————————————————————————————————————–

    I figure its probably something dumb that I am not getting.

    Thank you for your time.

  • #26876

    Participant
    Points: 41
    Rank: Member

    When you use Invoke-Command you're asking the remote computer to launch PowerShell and run the cmdlet(s) you're sending. The variables that you have set only exist in the local instance of PowerShell so the remote machine doesn't know about them.

    In PowerShell 3 and newer you can use $using to pass through local variables to the remote computer. I'm not sure if it supports splatting though so I've broken those out.

    See about_Remote_Variables for more information.

    Invoke-command $computername -scriptBlock {New-SelfSignedCertificate -CertStoreLocation $using:CertStoreLocation -DNSname $using:dnsname}
    
  • #26881

    Participant
    Points: 0
    Rank: Member

    YES!!!! It works! Man that's so easy, I can make certificates 1 handed!

    Now for world domination!!!

    Thank you Matt!

The topic ‘Invoke Generate Self Signed Certificate’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort