N
noellapin
Checkpoint-Computer is a command to make a restore point in PowerShell script.
Sometimes it repeats "99% Completed" for hours.
Does anyone know the cause?
Quick remedy: Making it manually with the Control Panel.
Not using a script, it always succeeds.
But I hope to make restore points automatically.
---
I did chkdsk, dism, sfc, stopped anti-virus, erased restore points and shadow copies,
tried PowerShell ISE and Visual Studio Code, but couldn't get any hint.
So I made the files below, but it does not solve the problem.
Also, I think there should be shorter methods to produce the same result.
[_RestorePoint.bat]
@set "this=%0%"
@PowerShell "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)" | find /i "True" > nul
@if ErrorLevel 1 (
echo not admin, %this% will exit
exit
)
set /a "loop_count=0"
:label_loop
set /a "loop_count=%loop_count% + 1"
@if %loop_count% gtr 3 (
echo time up, when it fails, it fails
goto label_end
)
PowerShell C:\tmp\_RestoreDate.ps1 | find /i "new"
if %ErrorLevel% equ 0 goto label_end
Reg import C:\tmp\_PermitRestoreTime.reg
taskkill /f /fi "ImageName eq PowerShell.exe" /fi "WindowTitle eq Administrator: CreatingRestorePoint"
start "CreatingRestorePoint" /RealTime PowerShell -ExecutionPolicy Unrestricted -OutputFormat XML -WindowStyle Minimized -Command " Checkpoint-Computer -Description 'daily' -RestorePointType 'MODIFY_SETTINGS' "
timeout 1800 > nul
taskkill /f /fi "ImageName eq PowerShell.exe" /fi "WindowTitle eq Administrator: CreatingRestorePoint"
goto label_loop
:label_end
PowerShell Get-ComputerRestorePoint
exit
[eof]
[_RestoreDate.ps1]
$currentUser = New-Object Security.Principal.WindowsPrincipal $( [Security.Principal.WindowsIdentity]::GetCurrent() )
$testResult = $currentUser.IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator )
If ( $testResult -eq $False ) {
echo "not admin"
Exit
}
$targetTime = (Get-Date).AddMinutes( -30 )
$ts = $targetTime.ToString( "MM/dd/yyyy HH:mm" )
$a = Get-ComputerRestorePoint | Select-Object CreationTime
ForEach ( $b in $a ) {
$c = $b.CreationTime
$d = $c.ToString()
$e = $d.SubString( 0, 14 )
$f = $e + '-00:00' #using local time not utc
$g = [DateTime]:arseExact( $f, 'yyyyMMddHHmmsszzz', $null )
$gs = $g.ToString( "MM/dd/yyyy HH:mm" )
if ( $g -gt $targetTime ) {
Write-Output $( 'new restore point:' + $gs + ' > now - 30min:' + $ts )
} else {
Write-Output $( 'old restore point:' + $gs + ' <= now - 30min:' + $ts )
}
}
[eof]
[_PermitRestoreTime.reg]
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore]
"SystemRestorePointCreationFrequency"=dword:00000001
[eof]
Continue reading...
Sometimes it repeats "99% Completed" for hours.
Does anyone know the cause?
Quick remedy: Making it manually with the Control Panel.
Not using a script, it always succeeds.
But I hope to make restore points automatically.
---
I did chkdsk, dism, sfc, stopped anti-virus, erased restore points and shadow copies,
tried PowerShell ISE and Visual Studio Code, but couldn't get any hint.
So I made the files below, but it does not solve the problem.
Also, I think there should be shorter methods to produce the same result.
[_RestorePoint.bat]
@set "this=%0%"
@PowerShell "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)" | find /i "True" > nul
@if ErrorLevel 1 (
echo not admin, %this% will exit
exit
)
set /a "loop_count=0"
:label_loop
set /a "loop_count=%loop_count% + 1"
@if %loop_count% gtr 3 (
echo time up, when it fails, it fails
goto label_end
)
PowerShell C:\tmp\_RestoreDate.ps1 | find /i "new"
if %ErrorLevel% equ 0 goto label_end
Reg import C:\tmp\_PermitRestoreTime.reg
taskkill /f /fi "ImageName eq PowerShell.exe" /fi "WindowTitle eq Administrator: CreatingRestorePoint"
start "CreatingRestorePoint" /RealTime PowerShell -ExecutionPolicy Unrestricted -OutputFormat XML -WindowStyle Minimized -Command " Checkpoint-Computer -Description 'daily' -RestorePointType 'MODIFY_SETTINGS' "
timeout 1800 > nul
taskkill /f /fi "ImageName eq PowerShell.exe" /fi "WindowTitle eq Administrator: CreatingRestorePoint"
goto label_loop
:label_end
PowerShell Get-ComputerRestorePoint
exit
[eof]
[_RestoreDate.ps1]
$currentUser = New-Object Security.Principal.WindowsPrincipal $( [Security.Principal.WindowsIdentity]::GetCurrent() )
$testResult = $currentUser.IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator )
If ( $testResult -eq $False ) {
echo "not admin"
Exit
}
$targetTime = (Get-Date).AddMinutes( -30 )
$ts = $targetTime.ToString( "MM/dd/yyyy HH:mm" )
$a = Get-ComputerRestorePoint | Select-Object CreationTime
ForEach ( $b in $a ) {
$c = $b.CreationTime
$d = $c.ToString()
$e = $d.SubString( 0, 14 )
$f = $e + '-00:00' #using local time not utc
$g = [DateTime]:arseExact( $f, 'yyyyMMddHHmmsszzz', $null )
$gs = $g.ToString( "MM/dd/yyyy HH:mm" )
if ( $g -gt $targetTime ) {
Write-Output $( 'new restore point:' + $gs + ' > now - 30min:' + $ts )
} else {
Write-Output $( 'old restore point:' + $gs + ' <= now - 30min:' + $ts )
}
}
[eof]
[_PermitRestoreTime.reg]
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore]
"SystemRestorePointCreationFrequency"=dword:00000001
[eof]
Continue reading...