Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $restore_path = "C:\TempRestorePoint"
- function get_volumes() {
- $volumesText = vssadmin list volumes
- $volumes = @{}
- for ($count = 0; $count -lt $volumesText.Length; $count++) {
- if ($volumesText[$count].StartsWith("Volume path")) {
- $letter = $volumesText[$count].Split(" ")[2]
- if ($letter.StartsWith("\\") -eq $false) {
- $name = $volumesText[$count+1].Split(" ")[6]
- $volumes.Add($letter,$name)
- $count++
- }
- }
- }
- return $volumes
- }
- function get_volume_name() {
- $volumes = get_volumes
- $index = 0
- foreach ($key in $volumes.Keys) {
- $index ++
- Write-Host "Drive $key"
- }
- $volName = Read-Host -Prompt "Please enter a drive letter"
- $volName = $volName+":\"
- While($true) {
- if ($volumes.ContainsKey($volName)) {
- return $volumes[$volName]
- } else {
- $volName = Read-Host -Prompt "Please enter an EXISTING drive letter"
- $volName = $volName+":\"
- }
- }
- }
- function get_vss_objects() {
- $volumeName = get_volume_name
- $vss = vssadmin list shadows
- $vss_objects = @()
- for ($count = 1; $count -lt $vss.Count; $count++)
- {
- if ($vss[$count] -like "*$volumeName*") {
- $date = $vss[$count-2].Split(" ")[10]
- $day = $date.Split(".")[0]
- $month = $date.Split(".")[1]
- $year = $date.Split(".")[2]
- $time = $vss[$count-2].Split(" ")[11]
- $hours = $time.Split(":")[0]
- $minutes = $time.Split(":")[1]
- $scvol = $vss[$count+1].Split(" ")[12]
- $vss_object = New-Object psobject
- $vss_object | Add-Member NoteProperty day ([convert]::ToInt32($day,10))
- $vss_object | Add-Member NoteProperty month ([convert]::ToInt32($month,10))
- $vss_object | Add-Member NoteProperty year ([convert]::ToInt32($year,10))
- $vss_object | Add-Member NoteProperty hours ([convert]::ToInt32($hours,10))
- $vss_object | Add-Member NoteProperty minutes ([convert]::ToInt32($minutes,10))
- $vss_object | Add-Member NoteProperty scvol $scvol
- $vss_objects += $vss_object
- }
- }
- return $vss_objects
- }
- function get_vss_objects_for_day($vss_objects) {
- # ASK FOR YEAR #
- $first_year = $vss_objects[0].year
- $this_year = (Get-Date).Year
- if ($this_year -eq $first_year) {
- # only this_year
- $year = $this_year
- } else {
- # from first_year until this_year
- $years = @()
- for ($year = $first_year; $year -le $this_year; $year++) {
- $years += $year
- }
- $answerOK = $false
- do {
- $year = [convert]::ToInt32((Read-Host -Prompt "Please choose a year"),10)
- if ($years.contains($year)) {
- $answerOK = $true
- } else {
- foreach ($wr_year in $years) {
- Write-Host $wr_year
- }
- }
- } while ($answerOK -eq $false)
- }
- # ASK FOR YEAR END #
- # ASK FOR MONTH #
- $vss_objects = $vss_objects | Where {$_.year -eq $year}
- $first_month = $vss_objects[0].month
- $last_month = $vss_objects[$vss_objects.Length-1].month
- $months = @()
- for ($month = $first_month; $month -le $last_month; $month++) {
- $months += $month
- }
- $answerOK = $false
- do {
- $month = [convert]::ToInt32((Read-Host -Prompt "Please choose a month"),10)
- if ($months.contains($month)) {
- $answerOK = $true
- } else {
- foreach ($wr_month in $months) {
- Write-Host $wr_month
- }
- }
- } while ($answerOK -eq $false)
- # ASK FOR MONTH END #
- # ASK FOR DAY #
- $vss_objects = $vss_objects | Where {$_.month -eq $month}
- $first_day = $vss_objects[0].day
- $last_day = $vss_objects[$vss_objects.Length-1].day
- $days = @()
- for ($day = $first_day; $day -le $last_day; $day++) {
- $days += $day
- }
- $answerOK = $false
- do {
- $day = [convert]::ToInt32((Read-Host -Prompt "Please choose a date"),10)
- if ($days.contains($day)) {
- $answerOK = $true
- } else {
- foreach ($wr_day in $days) {
- Write-Host $wr_day
- }
- }
- } while ($answerOK -eq $false)
- # ASK FOR DAY END #
- return $vss_objects | Where {$_.year -eq $year -and $_.month -eq $month -and $_.day -eq $day}
- }
- $vss_objects = get_vss_objects
- do {
- $vss_day_objects = get_vss_objects_for_day($vss_objects)
- $vss_hashtable = @{}
- if ($vss_day_objects.GetType().IsArray) {
- $answerOK = $false
- do {
- for ($index = 0; $index -lt $vss_day_objects.Length; $index++) {
- $vss_hashtable.Add(($index+1),$vss_day_objects[$index].scvol)
- if ($vss_day_objects[$index].hours -lt 10) {
- $hour = "0" + $vss_day_objects[$index].hours
- } else {
- $hour = $vss_day_objects[$index].hours
- }
- if ($vss_day_objects[$index].minutes -lt 10) {
- $minute = "0" + $vss_day_objects[$index].minutes
- } else {
- $minute = $vss_day_objects[$index].minutes
- }
- Write-Host ($index+1) "-" $hour":"$minute "Uhr"
- }
- $promt = "Please enter number (1 - "+$vss_day_objects.Length+") or '0' for a different day"
- $choose = [convert]::ToInt32((Read-Host -Prompt $promt),10)
- if ($choose -eq 0 -or $vss_hashtable.Keys -contains $choose) {
- $answerOK = $true
- }
- } while ($answerOK -eq $false)
- } else {
- $answerOK = $false
- do {
- $vss_hashtable.Add(1,$vss_day_objects.scvol)
- if ($vss_day_objects.hours -lt 10) {
- $hour = "0" + $vss_day_objects.hours
- } else {
- $hour = $vss_day_objects.hours
- }
- if ($vss_day_objects.minutes -lt 10) {
- $minute = "0" + $vss_day_objects.minutes
- } else {
- $minute = $vss_day_objects.minutes
- }
- Write-Host "1 -" $hour":"$minute
- $choose = [convert]::ToInt32((Read-Host -Prompt "Please confirm with '1' or enter '0' for a different day"),10)
- if ($choose -eq 0 -or $vss_hashtable.Keys -contains $choose) {
- $answerOK = $true
- }
- } while ($answerOK -eq $false)
- }
- } while ($choose -eq 0)
- $shadow_path = $vss_hashtable[$choose]+"\"
- if (Test-Path($restore_path)) {
- $message = "$restore_path already exists and will be over written. Continue?"
- $answer = [System.Windows.Forms.MessageBox]::Show($message,"Warnung",4)
- if ($answer -eq "No") {
- exit
- }
- cmd /c rmdir $restore_path
- }
- cmd /c mklink /D $restore_path $shadow_path
Advertisement
Add Comment
Please, Sign In to add comment