Forum Discussion
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.
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
- LainRobertsonSilver Contributor
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__VBCopper Contributor
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