Reputation: 468
What I want to do: copy the contents of user profiles to a different location as a backup before deleting the profile.
How I'm trying to do it: use powershell with copy-item -recurse -path profileName
Is there any kind of way to exclude junction points?
I of course get weird stuff from the junction points. I guess the best thing would be to copy everything including the junction points, but even if I have to exclude them to get this to work, I could carefully leave them in place when restoring a profile because I won't be doing that often (hopefully never). Anyway, I can use -exclude and name all of the junction points that I find at the root of the profile, but then there are subfolder junction points like appdata\local\application data. That one will actually succeed in copying in a loop until the folder name gets too big. Big fail. Anyway, it would be awesome if I could do something like -filter {$_.attributes -notmatch "ReparsePoint"}, but of course filter only works with a string against the file/folder name. If I use Get-ChildItem -path profileLocation, I have to use -force or I'll miss any hidden/system files. But it also means that I'll get the same junction points which can't be read with this command and will generate an error before I can filter it out with a pipe Where-Object and pipe that to copy-item. Also, I'm guessing that method would be really slow. So, either way it looks like the only option is to use -exclude and type in all of the subfolder junction points. Nothing more straightforward?
Should I just give up on Powershell commands and use Robocopy.exe?
Upvotes: 2
Views: 1628
Reputation: 26170
For sure it s simplier with robocopy. What you could do with PS is to get the list of mountpoints from win32_volume (search for volume that doesnt have a drive letter). Then you can exclude any file having it's path matching that names. Something like this :
$exclude=gwmi win32_volume |?{$_.driveletter -eq $null} |select -expand name
ls C:\mountpoints\ -Recurse |%{
if( $_.PSIscontainer -eq $true) {$dir=$_.fullname}
else {$dir=$_.directoryname}
if ($exclude.trim('\') -notcontains $dir){ #copy here}}
Upvotes: 0