Appdata file copy to logged on user

//Appdata file copy to logged on user
Appdata file copy to logged on user2017-01-25T22:44:35+00:00

The Toolkit Forums General Appdata file copy to logged on user

  • Author
  • Matt
    Post count: 11

    Forgive the formatting, first post:

    The scenario: When deploying an SCCM app under the system context, I wanted to be able to copy a license file to the logged-on user’s appdata folder.

    The Result:
    #Copy license file to user
    $User = $($CurrentLoggedOnUserSession.Username)
    Write-Log -Message “User Targeted for Install: $User” -Source ‘Target-User’ -LogType ‘CMTrace’
    $Paths = Get-UserProfiles | Select-Object -ExpandProperty ‘ProfilePath’
    foreach ($Path in $Paths) {
    if ($Path -match $User) {
    Write-Log -Message “Targeted User Profile: $Path” -Source ‘Target-User’ -LogType ‘CMTrace’
    Robocopy “$dirSupportFiles” “$path\appdata\roaming\<appfolder>” license.xml

  • Francois
    Post count: 105


    WHy not using Execute-ProcessAsUser?


    • Matt
      Post count: 11

      Default is: The active console user. If no console user exists but users are logged in, such as on terminal servers, then the first logged-in non-console user.

      Multiple reasons:
      1. Wouldn’t I then need to relocate the license file to a non-admin directory first (rather than ccmcache)?
      2. I can now expand the above code to work with multiple active users.
      3. Doesn’t depend on task scheduler.

  • Aman
    Post count: 53

    I think it makes sense to have a dedicated function for this. We might add this in the next major version.

    Thank you

You must be logged in to reply to this topic.