1

I use below batch script to copy a file from USB to Downloads of a current user. What should it be if I want to apply this in Powershell ? Please help.

The difficult part is to interpret these two %~dp0 and %userprofile% The destination profile should be current user profile not administrator profile if powershell is run in administrator.

Copy-Item -Path %~dp0Software\Browsers\ChromeStandaloneSetup64.exe" -Destination %userprofile%\downloads
VB88
  • 363
  • 1
  • 6
  • 16
  • https://stackoverflow.com/questions/36414500/dp0-equivalent-in-powershell-using-expand-archive-cmdlet may help and try `$Env:USERPROFILE` for the other thing. Not sure about running it as administrator. Maybe code the script to call the script dynamically with `$Env:USERPROFILE` as an argument and have the script elevate as administrator and use that first passed `$args[0]` as a variable to fill in the destrination path portion of the logic. Give some of these things a test and see how it goes for some quick GoogleFu and thoughts. https://ss64.com/ps/syntax-args.html – Vomit IT - Chunky Mess Style Aug 28 '22 at 02:56
  • This may help for the other logic idea for some starting points there: https://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator and here too https://stackoverflow.com/questions/7690994/running-a-command-as-administrator-using-powershell – Vomit IT - Chunky Mess Style Aug 28 '22 at 02:58

1 Answers1

0

This should work for you:

Copy-Item -Path "${PSScriptRoot}\Software\Browsers\ChromeStandaloneSetup64.exe" -Destination "$($env:USERPROFILE)\downloads"

Works whether you are running powershell as admin or not.

$PSScriptRoot is the PS equivalent and gets the directory of the running script.

$env:USERPROFILE is the equivalent of %userprofile%. Returns root path of logged in users documents.

Narzard
  • 3,557
  • 14
  • 27