Home > Net >  powershell Script to save users profile when they log off their session
powershell Script to save users profile when they log off their session

Time:10-02

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

  • Related