Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

save folders

$
0
0

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


Viewing all articles
Browse latest Browse all 6937

Trending Articles