D
D
Dmitry Shumov2019-03-07 10:31:06
PowerShell
Dmitry Shumov, 2019-03-07 10:31:06

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%

those. what I have is only suitable for the logon/logof script. But often, users do not log out of sessions (doing a forced logout is not an option) and you just need to go through C:\Users\%username%\ once a day

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2019-03-07
@dshumov

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 question

Ask a Question

731 491 924 answers to any question