My issue is if I used the move-item function it will delete the desktop folder, and I also don't want to move the 'recycling bin' app/shortcut as well as another custom file "logs.txt" Except for these 2 items, I want all the other folders, files, and shortcuts moved into the destination folder ("C:\Temp"). When I tried using move-item with the * (i.e. C:\Users\Username\Desktop*) to "move everything" but it only moved all the files and did not preserve the folders / folder structure. it just pulled all the files out of all the folders.
How do I move files and folders, while preserving folder structure/hierarchy, and excluding certain files (specifically the ones listed above) ?
the script will be used automatically to keep the user's desktop clean and tidy. the "Temp" folder is where unsorted files and directories should be store until the user properly sorts each one.
Here is what I have so far:
$dest = "C:\Temp\";
$currentPath = "$($env:USERPROFILE)\Desktop\";
try {
Move-Item -Path $currentPath -Destination $dest
}
catch {
...
}
Also tried this: (got the same results)
$dest = "C:\Temp\";
$currentPath = "$($env:USERPROFILE)\Desktop\";
try {
Get-ChildItem -Path $currentPath -Recurse | Move-Item -Destination $dest
}
catch {
...
}
Do I need to break it up and use the copy-item and remove-item functions to add the files to the new folder, and then delete the old locations i.e. the original copies on the desktop?