src/Administration/Get-XrmBackup.ps1
|
<# .SYNOPSIS Retrieve backup infos .DESCRIPTION Retrieve a backup from given instance .PARAMETER InstanceDomainName Instance domain name (myinstance => myinstance.crm.dynamics1.com) .PARAMETER BackupLabel Name of the backup .OUTPUTS PSCustomObject[]. Backups of the instance, as returned by the Power Platform API (label, notes, backupPointDateTime...): only those with the given label when BackupLabel is set. .EXAMPLE Connect-XrmAdmin -TenantId $tenantId -ApplicationId $applicationId -ClientSecret $clientSecret; $backups = Get-XrmBackup -InstanceDomainName "contoso-prod"; $backup = Get-XrmBackup -InstanceDomainName "contoso-prod" -BackupLabel "Before release 2.4"; .LINK https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Get-XrmBackup.md #> function Get-XrmBackup { [CmdletBinding()] [OutputType([PSCustomObject[]])] param ( [Parameter(Mandatory = $true)] [String] $InstanceDomainName, [Parameter(Mandatory = $false)] [String] $BackupLabel ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); Assert-XrmAdminConnected; } process { $instance = Get-XrmInstance -Name $InstanceDomainName; $backupData = Get-PowerAppEnvironmentBackups -EnvironmentName $instance.Id; $backups = $backupData.value; if ($PSBoundParameters.ContainsKey('BackupLabel')) { $backup = $backups | Where-Object -Property "label" -EQ -Value $BackupLabel; $backup; } else { $backups; } } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Get-XrmBackup -Alias *; |