PENDING Powershell script to copy user desktop and document to their hostname folder.

Nitin_ted

Well-Known Member
73
2
8
Hello everyone, I'm seeking advice on creating a PowerShell or batch script. The script should copy the "Documents" and "Desktop" files from the latest user folder in the "C:\Users" directory to a destination folder. I have already set up folders using hostnames, so I need the script to match the hostname with the corresponding destination folder and copy the files into it. Any guidance on how to accomplish this would be greatly appreciated.
 

Garth

Well-Known Member
Staff member
1,856
161
63
 
OP
Nitin_ted

Nitin_ted

Well-Known Member
73
2
8
i tried above link but its not working (not copying the file in order, and some of the folder/file not copy too). Can you suggest what i doing wrong here?

$source = (Get-ChildItem -Path "C:\Users" | where {$_.Name -ne "administrator"}).FullName
$destination = "\\server\ITD_Data\$env:ComputerName"
Copy-Item -Path $source -Destination $destination -Recurse
 

Garth

Well-Known Member
Staff member
1,856
161
63
i tried above link but its not working (not copying the file in order, and some of the folder/file not copy too). Can you suggest what i doing wrong here?

$source = (Get-ChildItem -Path "C:\Users" | where {$_.Name -ne "administrator"}).FullName
$destination = "\\server\ITD_Data\$env:ComputerName"
Copy-Item -Path $source -Destination $destination -Recurse
Assuming you are using ConfigMgr to deploy this script. it is to be expected as the UNC will not be accessible by the computer account. You will need to grant permission for this to work.

Also add logging to you script if you want to know what is going on.
 
  • Like
Reactions: baysti

Forum statistics

Threads
5,773
Messages
22,503
Members
12,691
Latest member
kenta