Public/Start-MSPBackup.ps1
Function Start-MSPBackup { [CmdletBinding(SupportsShouldProcess = $true)] [OutputType('System.String')] Param( [Parameter( HelpMessage = "The datasource" )] [ValidateSet('Exchange', 'FileSystem', 'MySql', 'NetworkShares', 'Oracle', 'SystemState', 'VMware', 'VssHyperV', 'VssMsSql', 'VssSharePoint')] [String[]]$Datasource ) Begin { Write-Verbose ('{0}:: Function started' -f $MyInvocation.MyCommand) $stdOutTempFile = [System.IO.Path]::GetTempFileName() $stdErrTempFile = [System.IO.Path]::GetTempFileName() $ArgArray = @( "-machine-readable", "-non-interactive", "control.backup.start", "-datasource $Datasource" ) } Process { If ($PSCmdlet.ShouldProcess("Datasource: $Datasource","Start Backup")) { $StartProcessParams = @{ FilePath = $Script:CmdPath ArgumentList = $ArgArray Wait = $true NoNewWindow = $true PassThru = $true RedirectStandardOutput = $stdOutTempFile RedirectStandardError = $stdErrTempFile ErrorAction = "SilentlyContinue" } $StartExe = Start-Process @StartProcessParams $ClientToolExitCode = $StartExe.ExitCode $ClientToolStandardOutput = Get-Content -Path $stdOutTempFile | Out-String $ClientToolStandardOutput = $ClientToolStandardOutput.Trim() $ClientToolStandardError = Get-Content -Path $stdErrTempFile | Out-String $ClientToolStandardError = $ClientToolStandardError.Trim() If ($stdOutTempFile -or $stdErrTempFile) { Remove-Item @RemoveItemParams } $ArgArray | Out-Null $ClientToolExitCode | Out-Null If ($null -ne $ClientToolStandardError) { $Output = $ClientToolStandardError } Else { $Output = $ClientToolStandardOutput } } } End { Write-Verbose ('{0}:: Function ended' -f $MyInvocation.MyCommand) Return $Output } } |