Update Misc/Fix-VSSBackup.ps1
Set defaults when no params given
This commit is contained in:
@ -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 ----------
|
# ---------- Helpers ----------
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message)
|
param([string]$Message)
|
||||||
@ -69,9 +82,9 @@ function Test-VssErrors {
|
|||||||
|
|
||||||
$filters = @(
|
$filters = @(
|
||||||
@{ LogName='Application'; ProviderName='VSS' },
|
@{ LogName='Application'; ProviderName='VSS' },
|
||||||
@{ LogName='System'; ProviderName='VolSnap' }, # Volsnap driver errors
|
@{ 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
|
@{ LogName='Application'; ProviderName='Windows Server Backup' } # WSB
|
||||||
)
|
)
|
||||||
|
|
||||||
$events = foreach ($f in $filters) {
|
$events = foreach ($f in $filters) {
|
||||||
@ -196,7 +209,7 @@ if ($RequireFailedWriter -and $failedWriters.Count -eq 0) {
|
|||||||
if ($shouldAct) {
|
if ($shouldAct) {
|
||||||
Write-Log "Services worden herstart. Aantal in lijst: $($ServiceList.Count)."
|
Write-Log "Services worden herstart. Aantal in lijst: $($ServiceList.Count)."
|
||||||
foreach ($svcName in $ServiceList) {
|
foreach ($svcName in $ServiceList) {
|
||||||
Restart-ServiceSafe -Name $svcName -ForceStop:$Force.IsPresent
|
Restart-ServiceSafe -Name $svcName -ForceStop:$ForceEffective
|
||||||
}
|
}
|
||||||
|
|
||||||
Start-Sleep -Seconds 5
|
Start-Sleep -Seconds 5
|
||||||
|
|||||||
Reference in New Issue
Block a user