From 9e6670b1e2d94219757cdbb1a10413347780c6c5 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Sat, 20 Jun 2020 16:32:55 -0700 Subject: [PATCH] Update fix-windows-expiration.ps1 Add try/catch for the regex matching --- Vagrant/scripts/fix-windows-expiration.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Vagrant/scripts/fix-windows-expiration.ps1 b/Vagrant/scripts/fix-windows-expiration.ps1 index 066e75f..ec2bcf7 100644 --- a/Vagrant/scripts/fix-windows-expiration.ps1 +++ b/Vagrant/scripts/fix-windows-expiration.ps1 @@ -18,7 +18,12 @@ if ($regex.Matches.Value -eq "grace time expired") { # If activation was successful, the regex should match 90 or 180 (Win10 or Win2016) $regex = cscript c:\windows\system32\slmgr.vbs /dlv | select-string -Pattern "\((\d+) day\(s\)" } -$days_left = $regex.Matches.Groups[1].Value +try { + $days_left = $regex.Matches.Groups[1].Value +} catch { + Write-Host "Unable to successfully parse the output from slmgr, not rearming" + $days_left = 90 +} if ($days_left -as [int] -lt 30) { write-host "Less than 30 days remaining before Windows expiration. Attempting to rearm..."