AddAdministrativeRestoreJob

This is a sample PowerShell script for AddAdministrativeRestoreJob. You may need to modify it to fit your needs and environment.

Copy
function RestoreData {
    param(
        [Parameter(Mandatory=$true)] $UserName                        # Dashboard username
        ,$Password                                                    # Dashboard password. Will prompt if blank or "*"
        ,[Parameter(Mandatory=$true)] $DashboardUrl                   # Dashboard URL. Example: https://vault.example.com/Dashboard
        ,[Parameter(Mandatory=$true)] [Guid] $CompanyId               # Company ID that contains the source device
        ,[Parameter(Mandatory=$true)] [Guid[]] $SourceDeviceIds       # Source device ID (or array) to restore files from 
        ,[Parameter(Mandatory=$true)] [Guid[]] $TargetDeviceIds       # Target device ID (or array) to put the restored files
        ,[string[]] $FoldersToRestore = $null                         # Array of folder names to restore
        ,[string[]] $SpecificFilesToRestore = $null                   # Array of file names to restore
        ,[string] $ExtensionGroupName = $null                         # Specific file extension to restore
        ,[string] $FileOrFolderNameSearchFilter = $null               # Restore files based on this search filter
        ,[bool] $RestoreTheMostRecentFileInstances = $true           
        ,[DateTime] $restoreTimeUtc = [DateTime]::UtcNow              # Date/Time to restore file from. 
        ,[bool] $RestoreFirstVersionAfterRestoreTimeIfFileDoesNotYetExist = $false 
        ,[bool] $RestoreToOriginalLocation = $false
        ,[string] $SpecificRestoreLocationPath = "C:\AdminRestoreLocation\{DeviceName}\{DateTime}"
    )

    if (!$Password -or ($Password -eq "*")) {
        $Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((read-host -assecurestring -Prompt "Enter the password for $UserName")))
    }
  
    # Load the WSDL into proxy object
    Write-Host "Loading the web service definition..."          
    $proxy = New-WebServiceProxy -Uri "$DashboardUrl/DashboardService.v.1.0.svc?WSDL" -Namespace "DashboardServiceReference" -Class "foo"

    [Guid] $submissionId = [Guid]::NewGuid()

    #Rules to apply when restoring the files
    [DashboardServiceReference.RestoreFileReplacementRules] $restoreFileReplacementRules = [DashboardServiceReference.RestoreFileReplacementRules]::DontRestoreFileIfItExistsInRestorationLocation                               

    #Create the web service reference
    [DashboardServiceReference.AdministrativeRestoreJobResult] $result = $null
    [DashboardServiceReference.AdministrativeRestoreJobInput] $in = New-Object DashboardServiceReference.AdministrativeRestoreJobInput
    [DashboardServiceReference.CallingContext] $callingContext = New-Object DashboardServiceReference.CallingContext

    #Set up calling credentials
    $callingContext.ContextIdentity = $Username
    $callingContext.AuthenticationToken = $Password
    $callingContext.TokenType = [DashboardServiceReference.AuthenticationTokenType]::Password
    $callingContext.TokenTypeSpecified = $true

    #Assign Job Parameters
    $in.SubmissionId = $submissionId
    $in.CompanyId = $CompanyId
    $in.SourceDeviceIds = $SourceDeviceIds
    $in.HostDeviceIds = $TargetDeviceIds
    $in.RestoreTheMostRecentFileInstances = $RestoreTheMostRecentFileInstances
    $in.RestoreTheMostRecentFileInstancesSpecified = $true
    if (!$RestoreTheMostRecentFileInstances)
    {
        $in.RestoreTimeUtc = $restoreTimeUtc
        $in.RestoreTimeUtcSpecified = $true
        $in.RestoreFirstVersionAfterRestoreTimeIfFileDoesNotYetExist = $RestoreFirstVersionAfterRestoreTimeIfFileDoesNotYetExist
        $in.RestoreFirstVersionAfterRestoreTimeIfFileDoesNotYetExistSpecified = $true
    }
    $in.RestoreFileReplacementRules = $restoreFileReplacementRules
    $in.RestoreFileReplacementRulesSpecified = $true
    $in.RestoreToOriginalLocation = $RestoreToOriginalLocation
    $in.RestoreToOriginalLocationSpecified = $true
    if (!$RestoreToOriginalLocation)
    {
        $in.RestoreToThisSpecificLocationPath = $SpecificRestoreLocationPath
    }
    $in.SpecificFilesToRestore = $SpecificFilesToRestore
    $in.FoldersToRestore = $FoldersToRestore
    $in.ExtensionCategoryToApplyToFolders = $ExtensionGroupName
    $in.FileOrFolderNameSearchFilterToApplyToFolders = $FileOrFolderNameSearchFilter

    #Now call the web service
    Write-Host "Submitting restore job..."
    [DashboardServiceReference.ServiceResponse] $serviceResponse = $proxy.AddAdministrativeRestoreJob($callingContext, $in, [ref] $result)

    #Deal with the response
    [string] $title = "Error"
    [string] $message = ""

    if ($serviceResponse) {
        switch ($serviceResponse.Status)
        {
            "Completed" {
            if ($result.OverallStatus -eq [DashboardServiceReference.OverallStatus]::Success)
            {
                $message = "Job submitted"
                $title = "Success"
            }
            else
            {
                $message = "Call completed but job was not submitted." + $result.Information
            }
            break
            }
            "InvalidCredentials" {
                $message = $serviceResponse.Information
                break
            }
            "InvalidInput" {
                #Deal with this
                $message = $serviceResponse.Information
                break
            }
            default {
                $message = $serviceResponse.Information + ". Response: " + $serviceResponse.Status.ToString()
            }
        }
        Write-Output "$title`: $message`r`n$($result.Information)"
    }
    else {
        Write-Output "Error: `$serviceResponse is null."
    }
}