I am trying to create a script in PowerShell which would save the users data from this path c:\Users\[user]\Documents when the user log off.
I currently have something which could work for a single nominal user however I'd like to have something which work dynamically for every users. Here is my current script:
Copy-Item -Path C:\Users\username\Documents\ -Destination \\SRVIMP02\save\Username -force -Recurse
CodePudding user response:
If you are wanting to use the current user name instead of a static name, you can leverage $env:username
. This should give you the current user name.
In your case the following example should work:
Copy-Item -Path C:\users\$($env:USERNAME)\documents\ -Recurse -Destination \SRVIMP02\save\$($env:USERNAME)\ -Force