Insert $user into a path


I am using “$User=Get-LoggedOnUser”
and I would like to use this:
Copy-File -Path “$dirSupportFiles\com.iliumsoft.ewallet.plist” -destination “C:\Users$user\AppData\Roaming\com.iliumsoft.ewallet.plist”

But instead I get this:
[02-09-2018 17:54:36.352] [Post-Installation] [Copy-File] :: Copy file in path [C:\Users\ME\Desktop\Ilium Software\eWallet\\x86\SupportFiles\com.iliumsoft.ewallet.plist] to destination [C:\Use

Thoughts? I am pretty new to PoSh in general…

Get- LoggedOnUser
Synopsis: Get session details for all local and RDP logged on users.
Get session details for all local and RDP logged on users using Win32 APIs. Get the following session details: NTAccount, SID, UserName, DomainName, SessionId, SessionName, ConnectState, IsCurrentSession, IsConsoleSession, IsUserSession, IsActiveUserSession, IsRdpSession, IsLocalAdmin, LogonTime, IdleTime, DisconnectTime, ClientName, ClientProtocolType, ClientDirectory, ClientBuildNumber

So how can I use this to insert the currently logged on user?


Why not using an active-setup?


How about something like this?

foreach ($LoggedOnUserSession in $LoggedOnUserSessions) {
[string[]]$UserProfile = (Get-UserProfiles | Where-Object {$_.NTAccount -eq $LoggedOnUserSession.NTAccount}).ProfilePath
Copy-File -Path “$dirSupportFiles\com.iliumsoft.ewallet.plist” -destination “$UserProfile\AppData\Roaming\com.iliumsoft.ewallet.plist”


The problem with that solution is you will catch already existing profiles. But at a moment a new user will logon and then you will not get it.


Francois, yeah, I know. He was looking for logged on users, so that’s what I figured he was looking to do.

If you need to copy the file to all profiles including the default user so that new users get it to you can do this…

[string[]]$ProfilePaths = Get-UserProfiles | Select-Object -ExpandProperty ‘ProfilePath’

foreach ($ProfilePath in $ProfilePaths) {
Copy-File -Path “$dirSupportFiles\com.iliumsoft.ewallet.plist” -destination “$ProfilePath\AppData\Roaming\com.iliumsoft.ewallet.plist”

1 Like

I appreciate the replies.

I will deploy this via SCCM with the condition that a user “must be logged in”. So technically I only need the currently logged in user. I’ve done this many times in batch by querying the registry and getting "", and then trimming off ""

I could also make two deployments: 1) Workstation only deployment (software install) that has a dependent 2) user only deployment - I can copy the file in “user context” in which I can use the username variable.

With all that said, I’d also like to move all “non-standard” deployments to PSADT as a standard. I don’t want a mixture of batch/VBS/PS/PSADT as eventually I’ll leave and I don’t want the next person having to deal with different solutions.

Maybe copying to all profiles including default is a good idea. This software meets an SEC requirement and must be on all end user devices.

I will try the above and post back Monday.

Thanks everyone for you’re input - much appreciated.

I am using Jim’s suggestion as it really solves any issues I currently have and may encounter.

I definitely need to start learning PoSh! Thanks Jim and thanks everyone else for the quick replies. I am now able to deploy this software domain-wide with no issues.

Matthew, glad to help. If you have any more questions, ask away

use $envAppData -> (e.g. C:\Users{username}\Appdata\Roaming)

Copy-File -Path “$dirSupportFiles\com.iliumsoft.ewallet.plist” -destination “$envAppData\com.iliumsoft.ewallet.plist”

This is a nice solution but I noticed, deployed by SCCM, that all existing profiles are updated except the current user profile?
Is there a solution to include the current user profile?

EDIT: I was wrong, it also works for CU