Public/Restore-WebsiteRootRemotely.ps1
function Restore-WebsiteRootRemotely { ############################################################################## #.SYNOPSIS # Restores website root files remotely (used with Backup-WebsiteRootRemotely) # #.DESCRIPTION # Use this function to maintain backups restore using Robocopy if deployment has failed # Detailed information about the Robocopy exit codes is provided in the end of the operaton # Robocopy log file (BACKUP_DIR\_SitecoreDeploymentPS\RobocopyRestoreLog.txt) # Reverts all changed files and deletes the newly created ones, except for excluded directories (if any) # Used with Backup-WebsiteRoot # #.PARAMETER SourceDir # Root directory of backups. (absolute path) # #.PARAMETER TargetDir # Website root directory (absolute path) # #.PARAMETER ComputerName # Name of the remote computer you will connect to # #.PARAMETER Username # Username # #.PARAMETER Password # Password # #.EXAMPLE # $sourceDir = "C:\backups" # $targetDir = "C:\inetpub\wwwroot\website" # $computerName = "ComputerName" # $username = "username" # $password = "password" # Restore-WebsiteRootRemotely -ComputerName $computerName -Username $username -Password $password -SourceDir $sourceDir -TargetDir $targetDir ############################################################################## [CmdletBinding()] Param ( $VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference'), [string]$SourceDir, [string]$TargetDir, [string]$ComputerName, [string]$Username, [string]$Password ) try { #region Begin $systemLog = NewSystemLog -Name "Restore-WebsiteRootRemotely" WriteLog -Path $systemLog -Message "OUTPUT: Starting remoting, please wait" #endregion Begin #region Process $session = NewRemoteSession -ComputerName $ComputerName -Username $Username -Password $Password -LogFile $systemLog WriteLog -Path $systemLog -Message "OUTPUT: Waiting result from remoting, please wait" $capturedResult = Invoke-Command -Session $session -ScriptBlock ${function:RestoreWebsiteRootRemotely} -ArgumentList $SourceDir, $TargetDir, $VerbosePreference foreach ($message in $capturedResult) { WriteLog -Path $systemLog -Message $message } #endregion Process } catch { RegisterException } } |