-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnable-ClientSystemRestore.ps1
More file actions
71 lines (62 loc) · 2.01 KB
/
Copy pathEnable-ClientSystemRestore.ps1
File metadata and controls
71 lines (62 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<#
#>
function Enable-ClientSystemRestore {
[CmdletBinding()]
param(
)
try {
Enable-ComputerRestore -Drive C: -ErrorAction Stop
$createRestorePoint = $True
}
catch{
$_
Exit 1
}
#determine disk % free
$DiskWMI = (Get-WmiObject win32_logicaldisk | Where-Object {$_.deviceID -eq 'C:'})
$PercentFree = (($DiskWMI.freespace/$DiskWMI.Size) * 100)
#if more than 20% free, enable system restore.
if ($PercentFree -ge 20){
try{
$SetPercentDiskUsage = 'vssadmin resize shadowstorage /for=c: /on=c: /MaxSize=10%'
Enable-ComputerRestore -Drive 'C:\' -ErrorAction Stop
$a = Invoke-Command {cmd /c $SetPercentDiskUsage}
$string = 'Successfully'
if ($a -match $string){
#System restore was not enabled, was able to activate, set flag for restore point to true
$createRestorePoint = $True
}
else {
#System restore was not enabled, not able to activate, setting flag for restore point to false
$createRestorePoint = $False
}
}
catch{
[System.Exception]
$ResultCode = $_
$ResultCode.Exception
$LASTEXITCODE
}
}
else{
#System restore was not enabled, not enough disk space available to activate system restore
$createRestorePoint = $False
Write-Output 'Not enough disk space free to enable system restore'
}
#if flag $createRestorePoint = true then create a restore point, otherwise sys restore could not be enabled
if ($createRestorePoint -eq $True){
try{
Checkpoint-Computer -description 'Self Heal Completed'
Write-Output 'Restore point created'
}
catch{
[System.Exception]
$ResultCode = $_
$ResultCode.Exception
}
}
else{
Write-Output 'Could not create restore point.'
}
}
Enable-ClientSystemRestore