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