Public/PersistentStore/Import-R1StoreBackup.ps1

# .ExternalHelp psRadiantOne-help.xml
function Import-R1StoreBackup {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    [OutputType([void])]
    param(
        [parameter(
            Mandatory = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateNotNullOrEmpty()]
        [string]$dn,

        [parameter(
            Mandatory = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateScript( { Test-Path -Path $_ -PathType Leaf })]
        [Alias('FullName')]
        [string]$Path
    )

    Begin {

        Assert-R1Session -RequireToken

    }#begin

    Process {

        $URI = Resolve-R1ServiceUrl -Service Namespace -Path "naming_contexts/$($dn | Get-EscapedString)/store/restore/upload"

        $UploadFile = Get-Item -Path $Path

        $Form = ConvertTo-MultipartFormData -Field @{
            file = $UploadFile
        }

        if ($PSCmdlet.ShouldProcess($dn, "Restore Directory Store from $($UploadFile.Name)")) {

            $null = Invoke-R1RestMethod -Uri $URI -Method POST -Body $Form.Body -ContentType $Form.ContentType

        }

    }#process

    End { }#end

}