Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any PowerShell script or piece of free or commercial utility software that could be run on a server on demand and which would copy a particular set of files from a particular location on all visible domain computers back to a central location?

So it would presumably establish a list of domain computers from Windows and for one each attempt to access a particular location on the C: drive and copy the files that I'm interested in back to the server.

The use of login scripts is not a runner here.

share|improve this question
Why not using batch files? – Paul Jul 31 '13 at 12:30
@AlanB If using a batch file is not an option. Your only other option is to write a program in the programming language of your choice that does this. – Ramhound Jul 31 '13 at 12:39
You asked if there was "any method, script or piece of software" but then in your last sentence you pretty much said that the first two things you wanted were not acceptable. – Jack Jul 31 '13 at 13:15
I'll change the question to make it clearer. – Alan B Jul 31 '13 at 13:31
@Paul - because while I do have remote access to the server I don't administer the network, and the people that do would be awkward about login scripts. – Alan B Jul 31 '13 at 13:32
up vote 0 down vote accepted

I'm not a IT employee at my firm, so I haven't run this code fully, so it might have some bugs.

$strCategory = "computer"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")

$colProplist = "name"
$s = foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

$computers = $colResults |% {$_.Properties} |% {$} | sort | select {"\\" + $_}

foreach ($computer in $computers)
    $path = "YourFolder/YourFile.txt"

    $computerPath = Join-Path -Path $computer -ChildPath $path
    $computerPath # Or do a Get-Child instead of defining YourFile.txt
    Copy-Item -Path $computerPath -Destination 'C:\test.txt'

If you encounter a problem with credentials, this is how you make a network drive, which you can supply credentials with:

$pwd = ConvertTo-SecureString "SuperSecurePassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("Administrator", $pwd)
$pd = New-PSDrive -Name O -PSProvider FileSystem -Root $remotePath -Credential $cred

And simply switch $computer with $pd.

Remember to close it afterwards, with

Remove-PSDrive -Name O
share|improve this answer
Great thanks, can work from that. – Alan B Jul 31 '13 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .