Appdata file copy to logged on user

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

1 Like

Hi,

WHy not using Execute-ProcessAsUser?

Thanks,

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.
1 Like

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

Thank you