Firstly apologies I’m very new to Powershell and PSADT.
I’m trying to copy some Teams Background files to the Users profiles and set a registry Key using PSADT and Intune. This Works on my test laptop when when running the script as as Admin.
When I deploy to the machine through Intune the registry key gets added but the files do not copy to the user profile. Do you have any ideas why this might not be working.
I have the script set to Run as an Admin so not sure if I need to run the file copy to the User Profile as the logged in User?
These are the commands I am using.
## <Perform Installation tasks here>
set-registrykey -key 'HKEY_LOCAL_MACHINE\SOFTWARE\INTUNE' -Name 'Teams Backgrounds' -Type 'Dword' -Value '1'
Copy-File -Path "$dirFiles\*.*" -Destination "C:\homeworking\Teams Backgrounds"
Copy-File -Path "C:\homeworking\Teams Backgrounds\*.*" -Destination "$env:USERPROFILE\AppData\Roaming\Microsoft\Teams\Backgrounds\Uploads"
When you run as as SYSTEM, $env:USERPROFILE will not be the name of the user logged-in.
It will be C:\WINDOWS\system32\config\systemprofile
PSADT does have this ARRAY called $usersLoggedOn
so you could do this:
Copy-File -Path "C:\homeworking\Teams Backgrounds\*.*" -Destination "$($usersLoggedOn)\AppData\Roaming\Microsoft\Teams\Backgrounds\Uploads"
Doing it this way is a bit risky because it will only work IF the target user is logged on at the time the PSADT script runs.
The better solution is user Active Setup as it will work on all user AS THEY LOGIN and works for existing and future users.
Thank you so much for the reply and the useful information
I’ve tested out the first suggestion using $usersLoggedOn
The files are still not copying to the Users profile. I’ve tested other locations on my PC and the copy works successfully, so just the issue getting it into the current logged on users profile. If you have any other suggestions I’d be most grateful
Copy-File -Path “C:\homeworking\Teams Backgrounds*.*” -Destination “$($usersLoggedOn)\AppData\Roaming\Microsoft\Teams\Backgrounds\Uploads”
I don’t understand how you got GWD\JNCA in the destination path. (weird)
I forgot to strip out the domain name and add *C:\Users* in front of the username.
Here’s an updated listing:
#log list of all logged-on users for troubleshooting.
$usersLoggedOn | Out-String | write-log
#Strip out the domain name and add **C:\Users\** in front of the username.
$CurrentUserProfile = $($usersLoggedOn).replace("GWD",'C:\users')
#Copy Teams backgrounds to the first logged-on user in the array
Copy-File -Path "C:\homeworking\Teams Backgrounds\*.*" -Destination "$CurrentUserProfile\AppData\Roaming\Microsoft\Teams\Backgrounds\Uploads"
Please, remember that this hack will only work for the user that launches the SCCM App.
If you want better, you’ll have to use Active Setup.
This worked!!! Thank you so much!!
This app will only run when the user is logged in so this we should be okay there.
Honestly thank you this has been a great help
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.