Author Posts

August 24, 2018 at 4:39 pm

Trying to run the dsfrbacklog, the sending members and receiving members are saved in variable. However on running the backlog report I need to enter 1 value from sending member to 1 value of receiving member. I am not sure how to loop this up.

Example

$sendingservers = (Get-DfsrConnection -DomainName $Domain | Where {$_.GroupName -eq $replicationgroup}).SourceComputerName

$receivingservers = (Get-DfsrConnection -DomainName $Domain | Where {$_.GroupName -eq $replicationgroup}).DestinationComputerName

foreach ($sendingserver in $sendingservers ) {

# Get backlog count with dfsrdiag

$backlogcount=Get-DfsrBacklog -GroupName $replicationgroup -FolderName  $replicationfolder -SourceComputerName $sendingserver -DestinationComputerName $receivingserver

 

In the above, I can run this for each sending member, but then it target to whole list of receiving member, then been for each receiving member.

So I am looking something like below or similar.

foreach ($sendingserver in $sendingservers  and  $receivingserver in  $receivingservers)

Any help will be greatly appreciated

August 24, 2018 at 5:26 pm

I have not DFS deployment to test this with, yet, there is no concept of doing this...

foreach ($sendingserver in $sendingservers  and  $receivingserver in  $receivingservers)

...that I am aware of or ever tried.

This is two separate ForLoops, nested. Which takes you down this path...

$sendingservers = 'S1','S2','S3'
$receivingservers = 'R1','R2','R3'

foreach ($sendingserver in $sendingservers)
{
    # other outloop action here
    'Processing Sending server list'
    $sendingserver 

    ForEach ($receivingserver in  $receivingservers)
    {
        # Inner loop actions here
        'Processing Receiving Server list'
        $sendingserver 
        $receivingserver 

    }

}

# Results

Processing Sending server list
S1
Processing Receiving Server list
S1
R1
Processing Receiving Server list
S1
R2
Processing Receiving Server list
S1
R3
Processing Sending server list
S2
Processing Receiving Server list
S2
R1
Processing Receiving Server list
S2
R2
Processing Receiving Server list
S2
R3
Processing Sending server list
S3
Processing Receiving Server list
S3
R1
Processing Receiving Server list
S3
R2
Processing Receiving Server list
S3
R3

… but are you sure you wan this, this way?

Can you show an end result that you are expecting?

August 25, 2018 at 7:08 am

The result I am expecting as below:-

$sendingservers = 'S1','S2','S3'
$receivingservers = 'R1','R2','R3'

Processing Receiving Server list
S1
R1

Processing Receiving Server list
S2
R2

Processing Receiving Server list
S3
R3

August 25, 2018 at 7:48 am

That means you have mapping between Receiving and Sending Servers.

You can have a hashtable with this mapping. Here mapping is done with index.

[Array]$SendingServers   = (Get-DfsrConnection -DomainName $Domain | Where-Object -FilterScript  {$_.GroupName -eq $replicationgroup}).SourceComputerName
[Array]$ReceivingServers = (Get-DfsrConnection -DomainName $Domain | Where-Object -FilterScript {$_.GroupName -eq $replicationgroup}).DestinationComputerName
$C = 0

$MappedHashTable = $SendingServers | Foreach-Object -Process {
                        @{ $_ = $ReceivingServers[$C] }
                        $C++
                    }

foreach ($SendingServer in $SendingServers ) {
    $BacklogCount = Get-DfsrBacklog -GroupName $replicationgroup -FolderName  $replicationfolder -SourceComputerName $sendingserver -DestinationComputerName $MappedHashTable[$sendingserver]
}

August 25, 2018 at 12:50 pm

Thanks kvprsoon, though hasttable didnt helped, but the array thing help me out what exactly i need to do.


Foreach ($Domain in $domains) {

 

# Get all replication groups

$replicationgroups= (Get-DfsReplicatedFolder -DomainName $Domain).GroupName

 

# Loop through each replication group

foreach ($replicationgroup in $replicationgroups) {

 

# Get servers for the current replication group

$replicationfolder = (Get-DfsReplicatedFolder -DomainName $Domain | Where {$_.GroupName -eq $replicationgroup}).FolderName

[Array]$SendingServers   = (Get-DfsrConnection -DomainName $Domain | Where-Object -FilterScript  {$_.GroupName -eq $replicationgroup}).SourceComputerName

[Array]$ReceivingServers = (Get-DfsrConnection -DomainName $Domain | Where-Object -FilterScript {$_.GroupName -eq $replicationgroup}).DestinationComputerName

 

$C = 0

# Loop through each replication member server

foreach ($sendingserver in $sendingservers ) {

$receivingserver= $ReceivingServers[$C]

$C++

foreach ($SendingServer in $SendingServers ) {

$BacklogCount = Get-DfsrBacklog -GroupName $replicationgroup -FolderName  $replicationfolder -SourceComputerName $sendingserver -DestinationComputerName $receivingserver

}

August 25, 2018 at 2:59 pm

If you are processing using an index, this is a more typical approach utilizing a for loop:

$sendingservers = 'S1','S2','S3'
$receivingservers = 'R1','R2','R3'

for ($i = 0;$i -le ($sendingservers.Count -1);$i++) {
    $sendingservers[$i]
    $receivingservers[$i]
}