Appdata file copy to logged on user

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

The Toolkit Forums General Appdata file copy to logged on user

  • Author
    Posts
  • Matt
    Participant
    Post count: 11
    #1870 |

    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
    }
    }

    • This topic was modified 10 months ago by  Matt. Reason: Ug format
  • Francois
    Participant
    Post count: 101

    Hi,

    WHy not using Execute-ProcessAsUser?

    Thanks,

    • Matt
      Participant
      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
    Keymaster
    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.