How to copy bulk of files/rename them

I have a config file: Agent File installed on 80 Servers with the same name “agent.conf” .
What I want to do is to copy all files from all adcomputers then rename them according to each server name to one localtion
Like $Computers = Get-ADComputers -Filter * | Select -Expand Name
then loop through each and go to C:\path and copy each file and attach $_computer name to that file

Hi

Look this link, it will provide what you need, https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/copy-item

Example 8: Copy a file to a remote computer and then rename the file

PS C:> $Session = New-PSSession -ComputerName “Server04” -Credential “Contoso\PattiFul”
PS C:> Copy-Item “D:\Folder004\scriptingexample.ps1” -Destination “C:\Folder004_Copy\scriptingexample_copy.ps1” -ToSession $Session

Same idea, but you’ll need to reverse it basically. Copy from remote computer and rename it with computername. Also you’ll need to have PS Remoting enabled on the computers, otherwise youll need to use \computername\c$\path, if that’s also enabled.

How I would do it, Collect your servers, test-connection that those are online, if not catch offline computers and if it is online, copy file with new name, also could catch servers that do not have the file for example.

Regards

Jarkko

thanks Jarkko. Figured it out

 $PCs = Get-ADComputer -filter * | Select -expand Name
foreach ($PC in $PCs) { Copy-Item -Path \\$PC\C$\File_agentd.conf -Destination \\DC1\C$\CFiles\File_agentd_$PC.conf}