MilesLogan
asked on
Copy file from multiple shares to one location v2
Hi EE
I had this question answered by oBdA below but I still need a bit of help .
https://www.experts-exchange.com/questions/29071695/Copy-file-from-multiple-shares-to-one-location.html
Both of those scripts work but the files are being overridden if they have a similar path .
example:
\\Server1\folder\folder2\f older3\Sam Accountnam e1
\\Server1\folder\folder2\f older3\Sam Accountnam e2
In the example above only the file for SamAccountname2 is being saved or overriding the file for SAmaccountName1
Why I am thinking it would be easier of the file names can just be saved as the entire path or just the last 7 characters of the path.
I had this question answered by oBdA below but I still need a bit of help .
https://www.experts-exchange.com/questions/29071695/Copy-file-from-multiple-shares-to-one-location.html
Both of those scripts work but the files are being overridden if they have a similar path .
example:
\\Server1\folder\folder2\f
\\Server1\folder\folder2\f
In the example above only the file for SamAccountname2 is being saved or overriding the file for SAmaccountName1
Why I am thinking it would be easier of the file names can just be saved as the entire path or just the last 7 characters of the path.
$File = 'logfile.log'
$Destination = 'C:\Temp\Location'
$CopyLog = 'C:\Temp\Location\_LogfileCopy.log'
Get-Content -Path .\shares.txt | ForEach-Object {
$Server, $Share, $SamAccountName = $_.Split('\', [StringSplitOptions]::RemoveEmptyEntries)[0..2]
$Result = $_ | Select-Object -Property @{n='SamAccountName'; e={$SamAccountName}}, @{n='Path'; e={$_}}, Error
Try {
Copy-Item -Path "$($_)\$($File)" -Destination "$($Destination)\$($SamAccountName)_$($File)" -ErrorAction Stop
} Catch {
$Result.Error = $_.Exception.Message
}
$Result
} | Export-Csv -NoTypeInformation -Path $CopyLog
ASKER
HI 0BdA
that was my mistake thinking the folder structure was the same for all but its not ...
What is the exact folder structure? Is "SamAccountName" always the folder containing "logfile.log"?
The structure is different for all unfortunately , the only unique item is the samaccountname at the end of the path,
Is SamAccountName unique over all servers and shares?
Yes, this is the only unique item across for all the shares that I need the file from .
Is the source server/source share relevant, or are you just interested in the contents?
I only care about the file I need to copy from the source .
that was my mistake thinking the folder structure was the same for all but its not ...
What is the exact folder structure? Is "SamAccountName" always the folder containing "logfile.log"?
The structure is different for all unfortunately , the only unique item is the samaccountname at the end of the path,
Is SamAccountName unique over all servers and shares?
Yes, this is the only unique item across for all the shares that I need the file from .
Is the source server/source share relevant, or are you just interested in the contents?
I only care about the file I need to copy from the source .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
insane ! you are just amazing .. I so appreciate this .
* What is the exact folder structure? Is "SamAccountName" always the folder containing "logfile.log"?
* Is SamAccountName unique over all servers and shares?
* Is the source server/source share relevant, or are you just interested in the contents?