The actual code that I am running in the SureBackup job is as follows:
Code: Select all
Param($TestVmIP)
$ReturnCode = 1
$CredObject = Import-Clixml -Path C:\ps\CredObject.xml
$ReturnCode = Invoke-Command -Credential $CredObject -Computername $TestVmIP -ErrorAction Stop -ScriptBlock{
# create an array of paths to search through
$folders = 'E:\Foldername\*'
# create an array of file names to look for
$files = 'budget2024.xlsx', 'exec-contacts.docx', 'pw.txt', 'payroll.docx'
Get-ChildItem -Path $folders -Include $files -File |
Get-FileHash -Algorithm MD5 |
Export-Csv -Path 'C:\ps\newhashes.csv' -UseCulture -NoTypeInformation
$oldHashes = Import-Csv "C:\ps\hashes.csv"
$newHashes = Import-Csv "C:\ps\newhashes.csv"
$compare = Compare-Object $oldHashes $newHashes -Property Hash, Path
if ($compare.SideIndicator -eq "<=" -or $compare.SideIndicator -eq "=>"){
$ReturnCode = 1
Write-Host "$ReturnCode"
Exit 1
}
else{
$ReturnCode = 0
Write-Host "$ReturnCode"
Exit 0
}
}
#exit $ReturnCode ## THIS WAS COMMENTED OUT TO TEST, NO CHANGES AS A RESULT
I am testing the manual run here by running these commands and calling the same PS script with a few lines commented out:
Code: Select all
$CredObject = Import-Clixml -Path C:\ps\CredObject.xml
Invoke-Command -ComputerName 172.30.253.3 -FilePath c:\ps\SB_manual.ps1 -credential $CredObject
Code: Select all
Param($TestVmIP)
$ReturnCode = 1
#$CredObject = Import-Clixml -Path C:\ps\CredObject.xml
#$ReturnCode = Invoke-Command -Credential $CredObject -Computername $TestVmIP -ErrorAction Stop -ScriptBlock{
# create an array of paths to search through
$folders = 'E:\ShareData\*'
# create an array of file names to look for
$files = 'budget2024.xlsx', 'exec-contacts.docx', 'pw.txt', 'payroll.docx'
Get-ChildItem -Path $folders -Include $files -File |
Get-FileHash -Algorithm MD5 |
Export-Csv -Path 'C:\ps\newhashes.csv' -UseCulture -NoTypeInformation
$oldHashes = Import-Csv "C:\ps\hashes.csv"
$newHashes = Import-Csv "C:\ps\newhashes.csv"
$compare = Compare-Object $oldHashes $newHashes -Property Hash, Path
if ($compare.SideIndicator -eq "<=" -or $compare.SideIndicator -eq "=>"){
$ReturnCode = 1
Write-Host "$ReturnCode"
Exit 1
}
else{
$ReturnCode = 0
Write-Host "$ReturnCode"
Exit 0
}
#}
#exit $ReturnCode
Regardless of that, running the script from the SB job itself will always return 0/success.
If anyone has any ideas or pointers, I would gladly welcome them as I cannot figure out what may be the cause here. Thanks all!
-Adam