Лучший отвечающий
Как удалить конкретную точку восстановления используя cmd/powershell/vbs/bat/...?

Вопрос
-
Использую для создания точки восстановления ярлык со свойствами:
C:\Windows\System32\cmd.exe /k "wmic.exe /Namespace:\\root\default Path SystemRestore Call CreateRestorePoint "Restore Point on Week", 100, 7"
либо через powershell:
powershell Checkpoint-Computer -Description 'Недельная точка восстановления' -restorepointtype 'Modify_Settings'
В любом из этих случаев, я сталкиваюсь с проблемой того - что всё-таки хотелось бы не плодить кучу точек с одним и тем же названием, а перед/после создания удалять прошлую с тем же самым названием. Проще говоря, создать сценарий, который создаёт точку восстановления, а в случаи уже её наличия - перезаписывает её. Прочие точки восстановления, которые созданы не этим сценарием - затрагивать не нужно.5 декабря 2016 г. 10:48
Ответы
-
Проверил, все нормально удаляет.
PS > Checkpoint-Computer -Description "Uninstall:New" -RestorePointType MODIFY_SETTINGS PS > vssadmin list shadows vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool (C) Copyright 2001-2005 Microsoft Corp. Contents of shadow copy set ID: {09f3a653-45d6-4000-b158-a43fd28bc520} Contained 1 shadow copies at creation time: 05.12.2016 21:11:26 Shadow Copy ID: {be83a43d-9f7b-469a-8c16-bb95e1c32a2a} Original Volume: (C:)\\?\Volume{963b77bf-f407-11e5-892c-806e6f6e6963}\ Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3 Originating Machine: DESKTOP Service Machine: DESKTOP Provider: 'Microsoft Software Shadow Copy provider 1.0' Type: ClientAccessibleWriters Attributes: Persistent, Client-accessible, No auto release, Differential, Auto recovered Contents of shadow copy set ID: {621d48a1-f8af-48aa-a70f-f3b3b4319778} Contained 1 shadow copies at creation time: 05.12.2016 21:12:44 Shadow Copy ID: {70f8ed33-1937-40e7-9ebe-6c66ad831a64} Original Volume: (C:)\\?\Volume{963b77bf-f407-11e5-892c-806e6f6e6963}\ Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy4 Originating Machine: DESKTOP Service Machine: DESKTOP Provider: 'Microsoft Software Shadow Copy provider 1.0' Type: ClientAccessibleWriters Attributes: Persistent, Client-accessible, No auto release, Differential, Auto recovered PS > (Get-PSDrive -Name C).Free/1gb 42,1612930297852 PS > Get-ComputerRestorePoint | Delete-ComputerRestorePoint 0 0 PS > (Get-PSDrive -Name C).Free/1gb 42,5499534606934
- Помечено в качестве ответа Anton Sashev Ivanov 15 декабря 2016 г. 7:56
5 декабря 2016 г. 18:14
Все ответы
-
https://gallery.technet.microsoft.com/scriptcenter/Script-to-delete-System-4960775a
#example usage: #"simulate" the deletion of all available System Restore Points Get-ComputerRestorePoint | Delete-ComputerRestorePoint -WhatIf #delete all System Restore Points older than 14 days $removeDate = (Get-Date).AddDays(-14) Get-ComputerRestorePoint | Where { $_.ConvertToDateTime($_.CreationTime) -lt $removeDate } | Delete-ComputerRestorePoint
Соответственно:
PS C:\> Get-ComputerRestorePoint Description : MyCheck SequenceNumber : 59 PS C:\> Get-ComputerRestorePoint | Where Description -eq "MyCheck" | Delete-ComputerRestorePoint
5 декабря 2016 г. 11:51 -
https://gallery.technet.microsoft.com/scriptcenter/Script-to-delete-System-4960775a
#example usage: #"simulate" the deletion of all available System Restore Points Get-ComputerRestorePoint | Delete-ComputerRestorePoint -WhatIf #delete all System Restore Points older than 14 days $removeDate = (Get-Date).AddDays(-14) Get-ComputerRestorePoint | Where { $_.ConvertToDateTime($_.CreationTime) -lt $removeDate } | Delete-ComputerRestorePoint
Соответственно:
PS C:\> Get-ComputerRestorePoint Description : MyCheck SequenceNumber : 59 PS C:\> Get-ComputerRestorePoint | Where Description -eq "MyCheck" | Delete-ComputerRestorePoint
В случаи powershell, в попытке моего воплощения выдаёт ошибку:
PS C:\WINDOWS\system32> Get-ComputerRestorePoint
CreationTime Description SequenceNumber EventType RestorePointType
------------ ----------- -------------- --------- ----------------
03.12.2016 23:43:43 Операция восстановления 3 BEGIN_SYSTEM_C... 6
05.12.2016 1:40:12 Практически всё работает 9 BEGIN_SYSTEM_C... 16
05.12.2016 13:46:10 Недельная точка восстановления 15 BEGIN_SYSTEM_C... MODIFY_SETTINGS
PS C:\WINDOWS\system32> Get-ComputerRestorePoint | Where Description -eq "Недельная точка восстановления" | Delete-ComputerRestorePoint
Delete-ComputerRestorePoint : Имя "Delete-ComputerRestorePoint" не распознано как имя командлета, функции, файла сценар
ия или выполняемой программы. Проверьте правильность написания имени, а также наличие и правильность пути, после чего п
овторите попытку.
строка:1 знак:85
+ ... on -eq "Недельная точка восстановления" | Delete-ComputerRestorePoint
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Delete-ComputerRestorePoint:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\WINDOWS\system32> Get-ComputerRestorePoint | Where Description -eq 'Недельная точка восстановления' | Delete-ComputerRestorePoint
Delete-ComputerRestorePoint : Имя "Delete-ComputerRestorePoint" не распознано как имя командлета, функции, файла сценар
ия или выполняемой программы. Проверьте правильность написания имени, а также наличие и правильность пути, после чего п
овторите попытку.
строка:1 знак:85
+ ... on -eq 'Недельная точка восстановления' | Delete-ComputerRestorePoint
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Delete-ComputerRestorePoint:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException5 декабря 2016 г. 14:25 -
Первой строкой привел, где взять скрипт Delete-ComputerRestorePoint - https://gallery.technet.microsoft.com/scriptcenter/Script-to-delete-System-4960775a
function Delete-ComputerRestorePoint{ <# .SYNOPSIS Function to Delete Windows System Restore points .DESCRIPTION Deletes Windows System Restore point(s) passed as an argument or via pipeline .PARAMETER restorePoints Restore point(s) to be deleted (retrieved and optionally filtered from Get-ComputerRestorePoint .EXAMPLE #use -WhatIf to see what would have happened Get-ComputerRestorePoint | Delete-ComputerRestorePoints -WhatIf .EXAMPLE #delete all System Restore Points older than 14 days $removeDate = (Get-Date).AddDays(-14) Get-ComputerRestorePoint | Where { $_.ConvertToDateTime($_.CreationTime) -lt $removeDate } | Delete-ComputerRestorePoints #> [CmdletBinding(SupportsShouldProcess=$True)]param( [Parameter( Position=0, Mandatory=$true, ValueFromPipeline=$true )] $restorePoints ) begin{ $fullName="SystemRestore.DeleteRestorePoint" #check if the type is already loaded $isLoaded=([AppDomain]::CurrentDomain.GetAssemblies() | foreach {$_.GetTypes()} | where {$_.FullName -eq $fullName}) -ne $null if (!$isLoaded){ $SRClient= Add-Type -memberDefinition @" [DllImport ("Srclient.dll")] public static extern int SRRemoveRestorePoint (int index); "@ -Name DeleteRestorePoint -NameSpace SystemRestore -PassThru } } process{ foreach ($restorePoint in $restorePoints){ if($PSCmdlet.ShouldProcess("$($restorePoint.Description)","Deleting Restorepoint")) { [SystemRestore.DeleteRestorePoint]::SRRemoveRestorePoint($restorePoint.SequenceNumber) } } } }
5 декабря 2016 г. 14:32 -
Первой строкой привел, где взять скрипт Delete-ComputerRestorePoint - https://gallery.technet.microsoft.com/scriptcenter/Script-to-delete-System-4960775a
function Delete-ComputerRestorePoint{ <# .SYNOPSIS Function to Delete Windows System Restore points .DESCRIPTION Deletes Windows System Restore point(s) passed as an argument or via pipeline .PARAMETER restorePoints Restore point(s) to be deleted (retrieved and optionally filtered from Get-ComputerRestorePoint .EXAMPLE #use -WhatIf to see what would have happened Get-ComputerRestorePoint | Delete-ComputerRestorePoints -WhatIf .EXAMPLE #delete all System Restore Points older than 14 days $removeDate = (Get-Date).AddDays(-14) Get-ComputerRestorePoint | Where { $_.ConvertToDateTime($_.CreationTime) -lt $removeDate } | Delete-ComputerRestorePoints #> [CmdletBinding(SupportsShouldProcess=$True)]param( [Parameter( Position=0, Mandatory=$true, ValueFromPipeline=$true )] $restorePoints ) begin{ $fullName="SystemRestore.DeleteRestorePoint" #check if the type is already loaded $isLoaded=([AppDomain]::CurrentDomain.GetAssemblies() | foreach {$_.GetTypes()} | where {$_.FullName -eq $fullName}) -ne $null if (!$isLoaded){ $SRClient= Add-Type -memberDefinition @" [DllImport ("Srclient.dll")] public static extern int SRRemoveRestorePoint (int index); "@ -Name DeleteRestorePoint -NameSpace SystemRestore -PassThru } } process{ foreach ($restorePoint in $restorePoints){ if($PSCmdlet.ShouldProcess("$($restorePoint.Description)","Deleting Restorepoint")) { [SystemRestore.DeleteRestorePoint]::SRRemoveRestorePoint($restorePoint.SequenceNumber) } } } }
5 декабря 2016 г. 15:56 -
Первой строкой привел, где взять скрипт Delete-ComputerRestorePoint - https://gallery.technet.microsoft.com/scriptcenter/Script-to-delete-System-4960775a
function Delete-ComputerRestorePoint{ <# .SYNOPSIS Function to Delete Windows System Restore points .DESCRIPTION Deletes Windows System Restore point(s) passed as an argument or via pipeline .PARAMETER restorePoints Restore point(s) to be deleted (retrieved and optionally filtered from Get-ComputerRestorePoint .EXAMPLE #use -WhatIf to see what would have happened Get-ComputerRestorePoint | Delete-ComputerRestorePoints -WhatIf .EXAMPLE #delete all System Restore Points older than 14 days $removeDate = (Get-Date).AddDays(-14) Get-ComputerRestorePoint | Where { $_.ConvertToDateTime($_.CreationTime) -lt $removeDate } | Delete-ComputerRestorePoints #> [CmdletBinding(SupportsShouldProcess=$True)]param( [Parameter( Position=0, Mandatory=$true, ValueFromPipeline=$true )] $restorePoints ) begin{ $fullName="SystemRestore.DeleteRestorePoint" #check if the type is already loaded $isLoaded=([AppDomain]::CurrentDomain.GetAssemblies() | foreach {$_.GetTypes()} | where {$_.FullName -eq $fullName}) -ne $null if (!$isLoaded){ $SRClient= Add-Type -memberDefinition @" [DllImport ("Srclient.dll")] public static extern int SRRemoveRestorePoint (int index); "@ -Name DeleteRestorePoint -NameSpace SystemRestore -PassThru } } process{ foreach ($restorePoint in $restorePoints){ if($PSCmdlet.ShouldProcess("$($restorePoint.Description)","Deleting Restorepoint")) { [SystemRestore.DeleteRestorePoint]::SRRemoveRestorePoint($restorePoint.SequenceNumber) } } } }
5 декабря 2016 г. 17:00 -
Проверил, все нормально удаляет.
PS > Checkpoint-Computer -Description "Uninstall:New" -RestorePointType MODIFY_SETTINGS PS > vssadmin list shadows vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool (C) Copyright 2001-2005 Microsoft Corp. Contents of shadow copy set ID: {09f3a653-45d6-4000-b158-a43fd28bc520} Contained 1 shadow copies at creation time: 05.12.2016 21:11:26 Shadow Copy ID: {be83a43d-9f7b-469a-8c16-bb95e1c32a2a} Original Volume: (C:)\\?\Volume{963b77bf-f407-11e5-892c-806e6f6e6963}\ Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3 Originating Machine: DESKTOP Service Machine: DESKTOP Provider: 'Microsoft Software Shadow Copy provider 1.0' Type: ClientAccessibleWriters Attributes: Persistent, Client-accessible, No auto release, Differential, Auto recovered Contents of shadow copy set ID: {621d48a1-f8af-48aa-a70f-f3b3b4319778} Contained 1 shadow copies at creation time: 05.12.2016 21:12:44 Shadow Copy ID: {70f8ed33-1937-40e7-9ebe-6c66ad831a64} Original Volume: (C:)\\?\Volume{963b77bf-f407-11e5-892c-806e6f6e6963}\ Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy4 Originating Machine: DESKTOP Service Machine: DESKTOP Provider: 'Microsoft Software Shadow Copy provider 1.0' Type: ClientAccessibleWriters Attributes: Persistent, Client-accessible, No auto release, Differential, Auto recovered PS > (Get-PSDrive -Name C).Free/1gb 42,1612930297852 PS > Get-ComputerRestorePoint | Delete-ComputerRestorePoint 0 0 PS > (Get-PSDrive -Name C).Free/1gb 42,5499534606934
- Помечено в качестве ответа Anton Sashev Ivanov 15 декабря 2016 г. 7:56
5 декабря 2016 г. 18:14