internal/functions/Copy-CFXRedirectedFolders.ps1
function Copy-CFXRedirectedFolders { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string] $FRX , [Parameter(Mandatory = $true)] [string] $DiskPath, [Parameter(Mandatory = $true)] [string] $RedirectedFoldersPath, [Parameter(Mandatory = $true)] [string] $SID ) Write-PSFMessage -Level Verbose -Message "Mounting VHD using FRX.exe: $Diskpath" $mountPoint = Mount-CFXProfile -FRX $FRX -DiskPath $DiskPath try{ $robocopyDestination = (Join-PSFPath $mountPoint.Path 'Profile') $robocopyLogPath = Join-PSFPath $env:Temp "$(Split-Path -Path $DiskPath -Leaf).robocopy.log" $roboCopyError = $null $fileACL = Get-ACL -Path $path $fileACL.SetOwner([System.Security.Principal.SecurityIdentifier] $SID) Set-ACL -Path $path -AclObject $fileACL -ErrorAction Stop # Set owner of Profile folder $profileACL = $robocopyDestination $profileACL.SetOwner([System.Security.Principal.SecurityIdentifier] $SID) Set-ACL -Path $robocopyDestination -AclObject $profileACL -ErrorAction Stop Copy-CFXRobocopy -Source $RedirectedFoldersPath -Destination $robocopyDestination -LogPath $robocopyLogPath -ErrorAction Stop } catch { $roboCopyError = $_ } finally{ Write-PSFMessage -Level Verbose -Message "Dismounting VHD using FRX.exe" Dismount-CFXProfile -DiskPath $DiskPath -Cookie $mountPoint.Cookie -FRX $FRX if($roboCopyError) {throw $roboCopyError} } } |