I have fileserver1 that has a bunch of files on it (dumps of db`s from previous night - separate process non-veeam)
Then, I backup this fileserver, and if the job is successful, I would like to delete those files. It works fine from command line, whether I start as powershell as admin or not. But when i run this from the post job option within the backup job, I get nothing, I have tried adding a separate script with a sleep 900 to see if it was because the backup job was still running but to no avail.
here`s what I am doing - any ideas are appreciated :
Code: Select all
$job = Get-VBRJob -Name "MYJobName"
$backupjob=Get-VBRBackupSession | Where {$_.jobId -eq $job.Id.Guid} | Sort EndTimeUTC -Descending | Select -First 1
if ( $backupjob.Result -eq "Success" )
{
$secureFileonprem = "C:\VeeamFLR\my-creds.txt"
$passwordonprem = Get-Content $secureFileonprem | ConvertTo-SecureString
$usernameonprem = "MyServer\Mylocalaccount"
$cred = New-Object System.Management.Automation.PSCredential ($usernameonprem, $passwordonprem )
$s = New-PSSession -ComputerName myfileserver.domain.com -Credential $cred
Invoke-Command -Session $s -Scriptblock {Remove-Item -Path D:\MyPath\dir\* -Recurse}
Remove-PSSession $s
}
Thanks