Update Misc/Fix-VSSBackup.ps1

Set defaults when no params given
This commit is contained in:
2025-09-22 10:58:03 +02:00
parent 79057c6661
commit bbc6789d93

View File

@ -54,6 +54,19 @@ param(
)
)
# ---------- Auto-defaults wanneer GEEN parameters zijn meegegeven ----------
$NoParams = ($PSBoundParameters.Count -eq 0)
if ($NoParams) {
try {
if (-not (Test-Path -LiteralPath 'C:\Temp')) {
New-Item -ItemType Directory -Path 'C:\Temp' -Force | Out-Null
}
} catch {}
$LogPath = "C:\Temp\VSS-Restart-$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
}
# Force-effectiviteit wordt later bepaald met $ForceEffective i.p.v. $Force direct te wijzigen
$ForceEffective = ($NoParams -or $Force.IsPresent)
# ---------- Helpers ----------
function Write-Log {
param([string]$Message)
@ -70,7 +83,7 @@ function Test-VssErrors {
$filters = @(
@{ LogName='Application'; ProviderName='VSS' },
@{ LogName='System'; ProviderName='VolSnap' }, # Volsnap driver errors
@{ LogName='Application'; ProviderName='Backup'; }, # Sommige backupapps loggen onder 'Backup'
@{ LogName='Application'; ProviderName='Backup' }, # Sommige backupapps loggen onder 'Backup'
@{ LogName='Application'; ProviderName='Windows Server Backup' } # WSB
)
@ -196,7 +209,7 @@ if ($RequireFailedWriter -and $failedWriters.Count -eq 0) {
if ($shouldAct) {
Write-Log "Services worden herstart. Aantal in lijst: $($ServiceList.Count)."
foreach ($svcName in $ServiceList) {
Restart-ServiceSafe -Name $svcName -ForceStop:$Force.IsPresent
Restart-ServiceSafe -Name $svcName -ForceStop:$ForceEffective
}
Start-Sleep -Seconds 5