Now you’re less likely to miss what’s been brewing in our knowledge base with this weekly digest
Please, try again later.
Per Veeam Support Policy: Custom script troubleshooting is not supported.
What's in Scope:
What's Out of Scope:
This article is intended to serve as a helpful resource from the Veeam Support team, offering straightforward guidance for those navigating the complexities of troubleshooting script failures. Please note, the advice provided within this article is given in good faith and without warranty.
This article provides advice on methods to troubleshoot PowerShell scripts that are executed as part of:
Pre-Freeze and Post-Thaw scripts are:
powershell.exe -ExecutionPolicy ByPass -Command try { . 'C:\Windows\{guid}\<script>.ps1' -ErrorAction Stop } catch { exit 1 }
Pre-Job and Post-Job scripts are:
powershell.exe -ExecutionPolicy ByPass -Command try {& '<path-to-script>' -ErrorAction Stop } catch { exit 1 }
This section will provide advice on changes you can make to your script to help with troubleshooting.
For this example, here is a simple script that identifies the most recently modified file in a folder and then copies it to a folder.
$LatestLog = get-childitem -Path 'C:\MonitoringLogs\' | sort-object LastWriteTime | select-object -last 1 Copy-Item $LatestLog.FullName D:\Backup\
Start-Transcript -path C:\temp\scriptlog.txt $LatestLog = get-childitem -Path 'C:\MonitoringLogs\' | sort-object LastWriteTime | select-object -last 1 Copy-Item $LatestLog.FullName D:\Backup\ Stop-Transcript
Start-Transcript -path C:\temp\scriptlog.txt $LatestLog = get-childitem -Path 'C:\MonitoringLogs\' | sort-object LastWriteTime | select-object -last 1 Write-Host $LatestLog Copy-Item $LatestLog.FullName D:\Backup\ Stop-Transcript
Start-Transcript -path C:\temp\scriptlog.txt $LatestLog = get-childitem -Path 'C:\MonitoringLogs\' | sort-object LastWriteTime | select-object -last 1 Write-Host $LatestLog Copy-Item $LatestLog.FullName D:\Backup\ -verbose Stop-Transcript
Now, this simple script, when run, will also write out a log file containg:
Test running the script from within the Guest OS of the VM using the account assigned within the Guest Processing settings of the job.
powershell.exe -ExecutionPolicy ByPass -Command "& {try {& 'C:\scripts\testscript.ps1' -ErrorAction Stop } catch { exit 1 }}"
Pre-Job/Post-Job scripts are executed on the Veeam Backup Server, using the account assigned to the Veeam Backup Service.
To begin direct script troubleshooting you will first need to identify which account Veeam will use to run the script, that way you can test your script using the same account.
Open services and check which account is listed in the 'Log On As' column for the Veeam Backup Service.
Or, check via PowerShell using:
Get-WmiObject Win32_Service -Filter "Name='VeeamBackupSvc'" | Select-Object Name,StartName
If the Veeam Backup Service is running under an actual user account, login as that account and test the script using the following command. This command is directly based on the method Veeam Backup & Replication uses to call the script:
powershell.exe -ExecutionPolicy ByPass -Command "& {try {& 'C:\scripts\testscript.ps1' -ErrorAction Stop } catch { exit 1 }}"
If the account assigned to the Veeam Backup Service is Local System, which is the most common configuration, testing the scripts manually will be a bit more difficult. There are two options for causing a script to be run using the account Local System.
This option will allow you to see any errors that are thrown immediately and allow you to rapidly rerun the script after modification to perform iterative testing more efficiently.
PsExec is available from Microsoft here: PsExec
To simulate the execution action Veeam Backup & Replication would perform as SYSTEM:
PsExec64.exe -s -i powershell.exe
powershell.exe -ExecutionPolicy ByPass -Command "& {try {& 'C:\path\to\script.ps1' -ErrorAction Stop } catch { exit 1 }}"
-ExecutionPolicy ByPass -Command "& {try {& 'C:\path\to\script.ps1' -ErrorAction Stop } catch { exit 1 }}"
Your feedback has been received and will be reviewed.
Please, try again later.
Please try select less.
This form is only for KB Feedback/Suggestions, if you need help with the software open a support case
Your feedback has been received and will be reviewed.
Please, try again later.