Implementation of creating shadow copies using Powershell

I made this after referring to other posts on the forum. It feels quite simple and does not require creating symbolic links.
(I remember seeing a post saying that you don’t have to worry about the length of the path. There is no limit, only the file/directory name has a length limit)


# Get UAC prompt
$userAccountControl = [System.Enum]::Parse([System.Security.Principal.WindowsBuiltInRole], "Administrator")
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$admin = $currentPrincipal.IsInRole($userAccountControl)

# If the user does not have administrator rights, prompt the user to upgrade their rights.
if (-not $admin) {
    Start-Process powershell.exe -Verb RunAs -ArgumentList ("-File", $MyInvocation.MyCommand.Path)
    exit
}

#Create volume shadow copy
$shadowCopyID = (Invoke-CimMethod -ClassName Win32_ShadowCopy -MethodName Create -Arguments @{ Volume = "C:\\" }).ShadowID
#Write-Output $shadowCopyID

$explorerPath = (Get-WmiObject -Namespace "root\CIMv2" -Class Win32_ShadowCopy | Where-Object { $_.ID -eq $shadowCopyID }).DeviceObject
#Write-Output $explorerPath

$combinedPath = $explorerPath + "\Users\Name"

rclone sync --create-empty-src-dirs  --delete-excluded  $combinedPath "Dest" -vv

#Delete ShadowCopy
Get-WmiObject Win32_ShadowCopy | Where-Object { $_.ID -eq $shadowCopyID } | Remove-WmiObject

Pause
3 Likes

thanks for the howto.

i am the writer of another rclone+vss howto guide
https://forum.rclone.org/t/i-want-to-share-how-to-enable-vss-for-rclone/11644/8

your script creates persistent snapshots.
imho, much better, safer, to only use non-persistent, auto-release, no writers

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.