It goes without saying, I'm new here, but like what I have seen possible so far.
Here's my question of "is it possible to achieve" for FFS from the experienced and advanced users:
Lets say, I have 50+ machines that I want to copy a dataset from.
PC1 C:\Folder\Dataset1
PC2 C:\Folder\Dataset2
PC3 C:\Folder\Dataset3
...
PC50 C:\Folder\Dataset50
I want to copy the Dataset# folder to \\Server\Path\Backups\Dataset#
The issue is (this issue seems to exist across many 'Sync' programs I have looked at or used), inside of each one of those Dataset# folders, is a folder for SQL Database Backups (i.e. C:\Folder\Dataset1\DatabaseBackup) that is backed up each hour of everyday, but the DatabaseBackup folder contains 48 hours of backups (so, C:\Folder\Dataset#\DatabaseBackup\backup1.7z, ..\backup2.7z, etc). So, I only want the newest "Backup%.7z" file out of that folder.
If this wasn't a big enough issue, the 2nd "Is it possible" Issue I might have is, all of the remote machines sit randomly in a range of IP's (i.e. 10.100.x.211, 10.101.x.211, 10.102.x.211, etc to something like 10.200.x.211).
So, I normally can do most of the Dataset# folders using powershell script, but am looking for a better solution than Powershell so I can get all the data instead of part of the dataset.
#Define the $Tab character. This is only used to space different values in the terminal in a presentable way.
$Tab = [char]9
$LocalFolder1 = "\\ServerPath\Folder_For_Storage\" #enclose in quotes incase of spaces in folder path names
$RemoteFolder1 = "C:\Folder_To_Copy_From\" #enclose in quotes incase of spaces in folder path names
#Clear the terminal screen.
Clear-Host
#Import the list of IPs from the file IPs.csv in the same folder as the script. File must have column header with "IP_Address" and list of addresses below.
$ComputerIPs = Import-Csv "C:\Scripts\IPs_To_Check.csv" #Currently checking against 2032 different IP addresses for 'Life'
#Save the start time and display it so at the end I can calculate total process time.
$StartTime = Get-Date
Write-Host "`n`n`n`n`n`nStart Time: $StartTime"
#Count the number of IPs in the file so I know how many times to iterate through the main process.
$IPCount = $ComputerIPs.Count
#Get the date so I can save the results to a file with the name yyyymmddhhmmss - Results.csv to the same folder as teh script.
$Date = Get-Date -UFormat "%Y%m%d%H%M%S"
<#
This is the guts of it.
- Read one IP
- Ping it
- If it returns succesfully, copy files to remote PC.
- Display the results on the terminal in a readable fashion
- Write the results to the "yyyymmddhhmmss - Results.csv".
#>
for ($i = 0; $i -lt $IPCount; $i++)
{
#Read the IP from the list now in memory.
$IP = $ComputerIPs.IP_Address.GetValue($i)
#Ping, if successful, carry on, else print a message in terminal and skip to next IP.
if(Test-Connection -ComputerName $IP -Quiet -Count 1){
$IP = $ComputerIPs.IP_Address.GetValue($i)
$Test = (Test-Connection -ComputerName $IP -Count 1 | Measure-Object -Property ResponseTime -Average).average
$Response = ($Test -as [int] )
Write-Host "The response time for$Tab" -ForegroundColor Green -NoNewline
Write-Host "$IP$Tab is " -ForegroundColor Green -NoNewline
Write-Host "$Response ms" -ForegroundColor Black -BackgroundColor white
$RemotePath1 = "\\$($IP)\c$\$($RemoteFolder1)"
#Delete Remote Connection if present. It won't work if multiple connections are created.
Write-Host "Checking if remote connection already exists for $($IP), if so deleting it (cannot have multiple connections)..."
NET USE /delete \\$($IP)\c$ 2>&1>null
#Create Remote Connection
Write-Host "Creating remote connection for $($IP)..."
NET USE \\$($IP)\c$ /u:$($IP)\RemoteUserName RemotePassword
#Copy File
Write-Host "Copying to files $($IP))..."
robocopy $RemotePath1 $LocalFolder1 /E /Z /COPY:DAT /R:10 /W:30 /V /ETA /TEE /XD DatabaseBackUps /UNILOG+:".\Transfer.log"
#Delete Remote Connection (clean up).
Write-Host "Deleting remote connection to $($IP)..."
NET USE /delete \\$($IP)\c$
}
else{
Write-Host "Could not connect to$Tab$IP" -ForegroundColor Red
}
#Update Progress Bar
$Percent = 100*$i/$IPCount
$Percent = [math]::Round($Percent, 2)
Write-Progress -Activity "Testing Connections and Gathering Job Info..." -Status "Progress: $Percent %" -PercentComplete $Percent
}
#Set progress bar to complete.
Write-Progress -Activity "Writing Locations..." -Status "Ready" -Completed
#Save the end time and calculate execution time
$EndTime = Get-Date
Write-Host "End Time: $EndTime"
$ExecutionTime = $EndTime - $StartTime
Write-Host "Execution Time: $ExecutionTime"