im working script that copy files and subfolders from one location to another and preserve the folder structute . heres mine
$UserName = $(Get-WMIObject -class Win32_ComputerSystem | select username).username
#Write-Output $UserName
new-item -name $UserName -path C:\data -type directory
copy-Item -Path C:\Users\xxxx\Documents\* -Destination C:\data\$UserName\Documents -recurse
copy-Item -Path C:\Users\xxxx\Desktop\* -Destination C:\data\$UserName\Desktop -recurse
copy-Item -Path C:\Users\xxxx\Favorites\* -Destination C:\data\$UserName\Favorites -recurse
the problem with this script that it does copy all files except few ones + it doesn't respect the folder structure.
and how to put the username variable in the path for the copy . i get errors when i use $ : can't find the access path . for my test i used the name of the user .
thanks for help