Insert $user into a path

//Insert $user into a path
Insert $user into a path2018-02-09T23:56:00+00:00

The Toolkit Forums General Insert $user into a path

  • Author
    Posts
  • Matthew
    Participant
    Post count: 4

    Hello,

    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\8.3.5.35516\x86\SupportFiles\com.iliumsoft.ewallet.plist] to destination [C:\Use
    rs\PSADT.QueryUser+TerminalSessionInfo\AppData\Roaming\].

    Thoughts? I am pretty new to PoSh in general…
    Thanks!

  • Matthew
    Participant
    Post count: 4

    Get- LoggedOnUser
    Synopsis: Get session details for all local and RDP logged on users.
    Description:
    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?

    • Francois
      Participant
      Post count: 105

      Hi,

      Why not using an active-setup?

      Thanks,

  • Jim
    Participant
    Post count: 54

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

    • Francois
      Participant
      Post count: 105

      Hi,

      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.

      Thanks,

    • Jim
      Participant
      Post count: 54

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

  • Jim
    Participant
    Post count: 54

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

    • Matthew
      Participant
      Post count: 4

      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.

    • Jim
      Participant
      Post count: 54

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

  • Matthew
    Participant
    Post count: 4

    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 “username@domain.com”, and then trimming off “@domain.com.”

    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.

  • Talha
    Participant
    Post count: 1

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

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

You must be logged in to reply to this topic.