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
  • 513

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,840