Skip to main content

Restart-VSS.ps1 Script

  • Oct 22, 2020 3:01 PM UTC
  • 9 comments
  • 2238 views

k00laidIT
Forum|alt.badge.img+8

One thing I’ve found as a Veeam customer is you often have to restart the VSS services on your SQL and other VSS aware servers. Here’s a script I wrote to do just that.

#   Name:   Restart-VSS.ps1
# Description: Restarts list of services in an array on VMs with a given vSphere tag. Helpful for Veeam B&R processing
# For more info on Veeam VSS services that may cause failure see https://www.veeam.com/kb2041

Import-Module VMware.PowerCLI

$vcenter = "vcenter.domain.com"
$services = @("SQLWriter","VSS")
$tag = "myAwesomeTag"
Connect-VIServer $vcenter
$vms = Get-VM |where {$_.Tag -ne $tag}

ForEach ($vm in $vms){
ForEach ($service in $services){
If (Get-Service -ComputerName $vm -Name $service -ErrorAction SilentlyContinue) {
Write-Host $service "on computer" $vm "restarting now."
Restart-Service -InputObject $(Get-Service -Computer $vm -Name $service);
}
}
}

 

9 comments

  • Oct 22, 2020 4:25 PM UTC

Extremely timely post!  I will definitely share this!  Thank you!


haslund
Forum|alt.badge.img+14
  • Mr. VMCE
  • Oct 22, 2020 4:52 PM UTC

Very nice script Jim, thank you for sharing. It seems this might not have been a one-off issue if you created this script, did you find the root cause of why the services need to be restarted?


k00laidIT
Forum|alt.badge.img+8
  • Author
  • Veeam Vanguard
  • Oct 22, 2020 5:19 PM UTC

Hey Ras, yes especially with Server 2016 The VSS writers are prone to hanging during long running Veeam jobs. You’ll find it the next job run when the job fails during the guest processing portion. Simply restarting the services fixes the issue.


CptAmerica
Forum|alt.badge.img
  • Comes here often
  • Mar 4, 2021 4:12 AM UTC

Just from the way the script is setup one may assume that the $tag variable would be the VMware tag applied to VMs that have AAiP enabled in their backups, but isn’t this line of code checking whether or not the VMware does not match the $tag variable?

$vms = Get-VM |where {$_.Tag -ne $tag}

Shouldn’t this be:

$vms = Get-VM |where {$_.Tag -eq $tag}

 Apologies if I’m mistaken. I haven’t yet played around with this script (need to actually start making use of VMware tags, hah), but I was just skimming through and that caught my eye and intuitively I feel like it should be checking to see if it does match.

Regardless, nice script! Thanks for sharing!


vNote42
Forum|alt.badge.img+12
  • On the path to Greatness
  • Mar 4, 2021 7:42 AM UTC

Nice script, thanks!

I thought not working VSS providers is a thing of the past (Windows 2000 und 2003). It seems to be like in fashion: everything comes back once in a while.


elchafik
  • New Here
  • May 25, 2021 8:28 AM UTC

Nice script, thanks ! ;-)


marcofabbri
Forum|alt.badge.img+12
  • On the path to Greatness
  • Sep 14, 2021 7:47 AM UTC

Why the need of restarting service @k00laidIT ?


regnor
Forum|alt.badge.img+14
  • Veeam MVP
  • Sep 15, 2021 9:39 AM UTC

Why the need of restarting service @k00laidIT ?

If you experience Guest Processing errors which mention VSS then most of the time a restart of the VSS services solves the problem. And if you regularly see such problems then a scheduled task/script can prevent those errors.

 


k00laidIT
Forum|alt.badge.img+8
  • Author
  • Veeam Vanguard
  • Sep 29, 2021 1:19 AM UTC

Oops sorry @marcofabbri, I went a little dark there for a while. Exactly what @regnor said; often you’ll see errors when using App Aware In-Guest Processing (AAIP) that are to the effect of “VSS Write not responding,” this is especially true in my experience with the SQL writers. The script just goes through and restarts the services so your next run AAIP should complete successfully.