Forum Discussion

Marc__VB's avatar
Marc__VB
Copper Contributor
Jun 22, 2022
Solved

Copying files in powershell

Hi,

 

I just start working with powershell and I'm already blocked with my first script.

 

I want of copy a file from one location to another and the name of the file is in a variable. I use the following cmd but nothing happens !

 

Copy-Item -Path "D:\PowerShell\Basis_Rappel_Folder\$a[$i].Pdfbestand" -Destination D:\PowerShell\Prog_Data\Output\Email\

 

In the variable $a[$i].Pdfbestand is the name of the file

 

Is there somebody who can help ?

 

thanks.

 

  

  • Marc__VB 

     

    Hi, Marc.

     

    To "break out" of the string mode and parse $a as a variable, you can use the following PowerShell construct:

     

    $(<PowerShell code and variables go in between, in here>)

     

    So, that would make a slight change to your command to the following:

    Copy-Item -Path "D:\PowerShell\Basis_Rappel_Folder\$($a[$i].Pdfbestand)" -Destination D:\PowerShell\Prog_Data\Output\Email\

     

    Cheers,

    Lain

2 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    Marc__VB 

     

    Hi, Marc.

     

    To "break out" of the string mode and parse $a as a variable, you can use the following PowerShell construct:

     

    $(<PowerShell code and variables go in between, in here>)

     

    So, that would make a slight change to your command to the following:

    Copy-Item -Path "D:\PowerShell\Basis_Rappel_Folder\$($a[$i].Pdfbestand)" -Destination D:\PowerShell\Prog_Data\Output\Email\

     

    Cheers,

    Lain

    • Marc__VB's avatar
      Marc__VB
      Copper Contributor

      LainRobertson 

      Hello Lain,

       

      Many Thanks for your replay. Now, with your advice my script works perfect.

      Problem solved !

      ps. this was a construction I didn't know.

       

      kind regards,

      marc

Resources