Move-CertificateToRemote.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<#
    .SYNOPSIS
        Moves a certificate with its chain to the store of a remote computer
 
    .DESCRIPTION
        Moves a certificate with its chain to the store of a remote computer
 
    .PARAMETER Certificate
        The certificate to move
 
    .PARAMETER MoveChain
        The password to use when exporting certificates with private key
 
    .PARAMETER ComputerName
        Target computer
 
    .PARAMETER Credential
        Target Credential
 
    .PARAMETER Session
        Target session
 
    .EXAMPLE
        $certificate=New-DomainSignedCertificate -Hostname "example.com" -CertificateAuthority ""
        $pfxPassword=ConvertTo-SecureString “password” -AsPlainText -Force
        $certificate|Move-CertificateToRemote -ComputerName EXAMPLE -PfxPassword $pfxPassword -MoveChain
 
    .LINK
        New-DomainSignedCertificate
 
    .LINK
        Copy-CertificateToRemote
#>


. $PSScriptRoot\Copy-CertificateToRemote.ps1

function Move-CertificateToRemote {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="Computer")]
        [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="Session")]
        [System.Security.Cryptography.X509Certificates.X509Certificate2]
        $Certificate,
        [Parameter(Mandatory=$false,ParameterSetName="Computer")]
        [Parameter(Mandatory=$false,ParameterSetName="Session")]
        [securestring]$PfxPassword=$null,
        [Parameter(Mandatory=$false,ParameterSetName="Computer")]
        [Parameter(Mandatory=$false,ParameterSetName="Session")]
        [switch]$MoveChain=$false,
        [Parameter(Mandatory=$true,ParameterSetName="Computer")]
        [AllowNull()]
        $ComputerName=$null,
        [Parameter(Mandatory=$false,ParameterSetName="Computer")]
        [pscredential]$Credential=$null,
        [Parameter(Mandatory=$true,ParameterSetName="Session")]
        [AllowNull()]
        $Session
    )
    Copy-CertificateToRemote @PSBoundParameters
    $Certificate|Remove-Item -Force
}