Powershell command not working if executed from batch script

arjun thampuran 1 Reputation point
2021-12-06T07:06:17.013+00:00

Objective : copy a file from any location browsed to a folder inside Program Files. I used powershell start-process command to copy file to the desired location. The command works perfectly well from cmd but after executing the command from batch script it doesn't seem to work.

Note: I have made required changes to command if it needs to be executed successfully form the batch scripts.

powershell -windowstyle hidden -Command "&{Start-Process powershell \"-ExecutionPolicy Bypass -NoProfile -NoExit -WindowStyle Hidden -Command \" copy \\"%6`\" `\"$Env:GRIDPRO/lc_mngr/gridpro.lic `\" `\" \" }"

This is the command that is executed when the script file runs

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SChalakov 10,266 Reputation points MVP
    2021-12-06T08:39:30.877+00:00

    Hi,

    can you please provide some more information:

    • What is the error messahe that you get when running the PowerShells part?
    • Why don't you do the copy with PowerShell directly:

    Use PowerShell to Copy Files and Folders to a New Location
    https://devblogs.microsoft.com/scripting/use-powershell-to-copy-files-and-folders-to-a-new-location/

    Copy-Item
    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.2

    Thanks and Regards,

    ----------

    If my reply was helpful please don't forget to upvote and/or accept as answer, thank you!
    Regards,
    Stoyan