-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ShadowStorage.ps1
More file actions
75 lines (54 loc) · 2.26 KB
/
Copy pathGet-ShadowStorage.ps1
File metadata and controls
75 lines (54 loc) · 2.26 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
72
73
74
75
<#
.SYNOPSIS
Zeigt die vorhandenen Schattenkopien des Laufwerks C: mit Zeitpunkt und
Speicherverbrauch.
.DESCRIPTION
Ermittelt ueber Win32_Volume die Geraete-ID von C: und listet die
zugehoerigen Eintraege aus Win32_ShadowCopy auf. Convert-WmiDateTime
rechnet die WMI-Zeitstempel in lesbare Datumsangaben um.
Beantwortet die beiden praktischen Fragen: bis wann reichen die
Vorgaengerversionen zurueck, und wie viel Platz kostet das.
.NOTES
Reine Abfrage, veraendert nichts. Das Gegenstueck zum Einrichten ist
Enable-ShadowCopy.ps1 im selben Ordner.
#>
$volume = Get-CimInstance -Query "SELECT * FROM Win32_Volume WHERE DriveLetter = 'C:' AND FileSystem = 'NTFS'"
$deviceID = $volume.DeviceID
# $shadowStorage = Get-CimInstance -Namespace root\cimv2 -ClassName Win32_ShadowStorage
# $shadowStorage | Where {$_.Volume.DeviceID -eq $deviceID}
$shadowCopiesFromVolumeC = Get-WmiObject Win32_ShadowCopy | Where-Object { $_.VolumeName -eq $deviceID }
function Convert-WmiDateTime {
param (
[string]$WmiDate
)
if ($WmiDate -match '^(\d{14})') {
$dt = [datetime]::ParseExact($Matches[1], 'yyyyMMddHHmmss', $null)
return $dt.ToString('yyyyMMdd_HHmmss')
}
return $null
}
$shadowCopiesFromVolumeC | Select-Object ID, VolumeName, DeviceObject, @{
Name = 'ErstelltAm'
Expression = { Convert-WmiDateTime $_.InstallDate }
}
# # Get the snapshot object (replace with your specific query)
# $snapshot = Get-CimInstance -ClassName Win32_ShadowCopy | Where-Object { $_.ID -eq "your_snapshot_id" }
# # Delete the snapshot
# if ($snapshot) {
# $snapshot | Remove-CimInstance
# Write-Host "Snapshot deleted."
# }
# else {
# Write-Host "Snapshot not found."
# }
# $deviceObject = $snapshot.DeviceObject + "\"
# Write-Host "Snapshot erstellt unter: $deviceObject"
# Write-Host "Erstelle symbolischen Link unter $LinkPath ..."
# cmd.exe /c "mklink /d `"$LinkPath`" `"$deviceObject`"" | Out-Null
# Write-Host "Schattenkopie ist bereit unter $LinkPath. Vorgang abschließen und beliebige Eingabetaste drücken ..."
# Pause
# Write-Host "Entferne symbolischen Link ..."
# [System.IO.Directory]::Delete($LinkPath, $true)
# Write-Host "Lösche VSS-Instanz ..."
# $snapshot.Delete() | Out-Null
# Write-Host "Fertig."