Jump to content
TechnicalHero

Transferring a file from LT Share

Recommended Posts

Hi All,

All I want to do st transfer a .dll from my LTShare to C:\Windows\LTSvc\packages\PowerShellScripts. Seemingly this is a bit tricky.

I can transfer it to C:\Users\LocalUser\Downloads\PowerShellScripts using PowerShells "Copy-Item" But I am not going to know the path of "LocalUser". There doesn't seem to be a variable for "User Profile" that I can specify. If there was, then job done.

Any idea how I can expose what the current logged in users profile path is and how to then cope ONE FILE to it?!

Any assistance would be great appreciated 🙂

image.thumb.png.03f4ecfd8cce2ec69cd1d572d9ab8ca4.png

Kind regards,

 

 

 

 

Share this post


Link to post
Share on other sites

Try to see if you can pass this to the script:

$cred = Get-Credential UserTo.RunAs

OR

$username = $env:username

So it goes something like this:

C:\Users\$username\Downloads\PowerShellScripts 

 

Share this post


Link to post
Share on other sites
On 6/12/2019 at 7:11 AM, TechnicalHero said:

Any idea how I can expose what the current logged in users profile path is and how to then cope ONE FILE to it?!

FYI, the profile path may not be that. To get it correctly you must either grab it from the registry, or use an environment variable that resolves to a path inside the profile and back up one level. Even one that references a path such as your appdata or documents can be redirected and not actually point to the profile path root.  I’m on mobile so I can’t suggest the “best” variable to try, but you can check available variables easily and find one to use. 

Share this post


Link to post
Share on other sites
On 6/16/2019 at 7:45 AM, DarrenWhite99 said:

environment variable that resolves to a path inside the profile

Windows has a %USERPROFILE% env var.  To elaborate a bit, the directory gets named to be unique so if the directory already existed for whatever reason (local user same name) it could be user.domain, user.001, etc.

On 6/12/2019 at 6:11 AM, TechnicalHero said:

transfer a .dll from my LTShare to C:\Windows\LTSvc\packages\PowerShellScripts

Perhaps I'm misunderstanding but can't you transfer it to %windir%\temp, the default location, and then move it where you want it?

Share this post


Link to post
Share on other sites
11 hours ago, SteveYates said:

Windows has a %USERPROFILE% env var.  To elaborate a bit, the directory gets named to be unique so if the directory already existed for whatever reason (local user same name) it could be user.domain, user.001, etc.

Perhaps I'm misunderstanding but can't you transfer it to %windir%\temp, the default location, and then move it where you want it?

From a scripting perspective, this is the problem with %USERPROFILE%:

From CMD.EXE on my computer:

C:\Windows\System32>whoami & echo %userprofile%
apexnt\dwhite
C:\Users\dwhite

From Automate Remote Command Prompt against my computer:

%windir%\system32> #whoami & echo %userprofile%
apexnt\apexservice
C:\WINDOWS\system32\config\systemprofile

%windir%\system32> whoami & echo %userprofile%
nt authority\system
C:\WINDOWS\system32\config\systemprofile

See the issue? There is no "good" way for Automate to find out what the user profile path is for the logged in user.

Wow.. This ended up being a pain. This should mostly work.  🤦‍♂️

powershell.exe "$user=(Get-WmiObject -Query 'select username from win32_computersystem').UserName; $objUser = New-Object System.Security.Principal.NTAccount($user); $SID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]).Value; $userprofile=(Get-ItemProperty \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$SID\").ProfileImagePath; (Get-Item -path \"Registry::HKEY_USERS\$SID\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\").GetValue('{374DE290-123F-4565-9164-39C4925E467B}', '', 'DoNotExpandEnvironmentNames') -replace '\%USERPROFILE\%',$userprofile"

This will work from Automate. It will determine the logged in user, their SID, their profile path, and the download folder location.  You can get other folders as well if you replace '{374DE290-123F-4565-9164-39C4925E467B}' with 'Desktop', 'Personal', etc.

Share this post


Link to post
Share on other sites
Posted (edited)

Oh I know about the agent running as localsystem (should have clarifed that...I was looking at the comment about the env var and the ones being discussed).  Nice you found a PS solution, I'll have to remember that.

I was just confused from the OP why the profile dir is necessary at all, based on the stated goal.

I would think Console Shell or Console Execute script functions should work to read the user's env var? (haven't tried)

Edited by SteveYates
clarity

Share this post


Link to post
Share on other sites

They should work correctly, if the command can complete the task. If you need the value back in the script, that’s where you have trouble. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...