Looking for some assistance…brand new to the forums and farily new to Powershell
I am trying to create a Powershell script that will allow me to go out to Users Computers (from a list of computers I have in a text file) and pull a few xml files from their C:\Users\UserAppData\Roaming\ folder and copy them to a folder on the server with the name of the computer (if possible).
I have the basics of my script down (variable to grab the computer names from my list and the general command to Copy-Item from one path to another on the server for each file, but where I need assistance is in how to tell the script (Via variable?) to look for each user on each computer and grab the files as well as how to tell the script to create a folder under the server share I created for that computer name and copy the files there…or even one step further and create subfolders under the created computername folder for each username on the system…
Any assistance is greatly appreciated…here is what I have so far. I have a Copy-Item for each file (there are two ) I need from each users folder. Trying to have a folder created under XML Backups for each ComputerName with possible subfolders for each user on that computer…
[pre]
$computers = Get-Content “C:\Computers.txt”
foreach ($computer in $computers) {
Invoke-Command -ComputerName $computer -ScriptBlock {Copy-Item -Path C:\Users\User\AppData\Roaming\FolderName\file.xml -Destination '\servershare\XML Backups'}
Invoke-Command -ComputerName $computer -ScriptBlock {Copy-Item -Path C:\Users\User\AppData\Roaming\FolderName\file.xml -Destination '\servershare\XML Backups'}
}
[/pre]
Again, thanks for any assistance you can provide as I work through this!