Answer the question
In order to leave comments, you need to log in
Powershell. Copying users' desktop content?
Good afternoon! Colleagues, help me cope with Powershell.
The essence of the problem: there is a terminal server, you need to periodically run through user profiles and copy all content from their Desktops and Documents ( except *.url and *.lnk ) to their personal folders on a network server. The problem is that I can't figure out how to do it with foreach . While it turns out to be done for one user:
Get-ChildItem -Path C:\Users\%username%\Desktop\* -Exclude *.url,*.lnk -Recurse | Copy-Item -Destination \\WSFS-01\Shares$\DOCS_users\%username%
Get-ChildItem -Path C:\Users\%username%\Documents\* -Exclude *.url,*.lnk -Recurse | Copy-Item -Destination \\WSFS-01\Shares$\DOCS_users\%username%
Answer the question
In order to leave comments, you need to log in
foreach($user in (Get-ChildItem C:\Users))
{
Get-ChildItem -Path "$($user.FullName)\Desktop\*" -Exclude *.url,*.lnk -Recurse | Copy-Item -Destination "\\WSFS-01\Shares$\DOCS_users\$($user.name)"
Get-ChildItem -Path "$($user.FullName)\Documents\*" -Exclude *.url,* .lnk -Recurse | Copy-Item -Destination "\\WSFS-01\Shares$\DOCS_users\$($user.name)"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question