Author Posts

May 8, 2015 at 10:12 am

Hi All – I am trying to write a script to set up a new DFSR Replication group. It works technically, but the results aren't really usable. The key goal here is to use an array to pipe in a long-ish table of folder names for the -contentpath in the Set-DFSRMembership cmdlet.

Everything up to the Foreach works swimmingly. The results are that for each item ($path) in the $source array, the set-dfsrmembership is run 18 times (thats how many lines are in $source), $foldername
increments each pass, but $path doesn't until the whole 18 item pass is complete. Then it starts back at the top of $source, $path increments to the 2nd item in the $source array, runs 18 times again,
incrementing $folder along the way. It does this over and over again until $path has incremented all the way through the the array. I think thats like 324 times total...

———————-
$Foldername = get-content C:\documents\OldDfs01_folder_names.txt

$source = get-content C:\documents\OldDfs01_folder_paths.txt

$dest = get-content C:\documents\NewDfs01_folder_paths.txt

$group = "dfs test 2"

New-DfsReplicationGroup -GroupName $group | Add-DfsrMember -ComputerName "OldDfs01","NewDfs01" | Format-Table dnsname,groupname -auto -wrap

New-DfsReplicatedFolder -GroupName $group -FolderName $Foldername

Add-DfsrConnection -GroupName $group -SourceComputerName OldDfs01 -DestinationComputerName NewDfs01

foreach ($path in $source) {

Set-DfsrMembership -GroupName $group -FolderName $foldername -ComputerName OldDfs01 -ContentPath $path –PrimaryMember $true -Force

}
———————

Here is a snip of the first few entries of the results (Ive only included the relevant bits):

Pass 1:

GroupName : dfs test 2
ComputerName : OldDfs01
FolderName : Prodn
ContentPath : n:\Prodn

GroupName : dfs test 2
ComputerName : OldDfs01
FolderName : Qa
ContentPath : n:\Prodn

GroupName : dfs test 2
ComputerName : OldDfs01
FolderName : Shipping
ContentPath : n:\Prodn

Pass 2:

GroupName : dfs test 2
ComputerName : OldDfs01
FolderName : Prodn
ContentPath : n:\Qa

GroupName : dfs test 2
ComputerName : OldDfs01
FolderName : Qa
ContentPath : n:\Qa

GroupName : dfs test 2
ComputerName : OldDfs01
FolderName : Shipping
ContentPath : n:\Qa

I suspect its something to do with the fact that that switch (-contentpath) doesn't accept piplining? Thoughts?

Thanks in advance for any assistance!

May 9, 2015 at 3:09 pm

$foldername is an array, while $path is a single string. If the content path is always going to be n:\foldername you can simplify the loop like this:

foreach ($folder in $foldername) {

Set-DfsrMembership -GroupName $group -FolderName $folder -ComputerName OldDfs01 -ContentPath "n`:`\$folder" –PrimaryMember $true -Force

I didn't actually test this so...
Hopefully all the characters make it through ok.

-Scott

May 11, 2015 at 8:55 am

Hi There –

Thanks for the reply. The behavior from your example ended up being the same as using the $path variable, however...

From a different discussion thread, I got it to work by putting all three txt files into one csv and calling each with a $item.(columnname).

———————-
$items = import-csv C:\SetDfsrPaths.csv

$group = "GenericGroupName"

New-DfsReplicationGroup -GroupName $group | Add-DfsrMember -ComputerName "OldDfs01","NewDfs01" | Format-Table dnsname,groupname -auto -wrap

New-DfsReplicatedFolder -GroupName $group -FolderName $items.FOLDERNAME

Add-DfsrConnection -GroupName $group -SourceComputerName OldDfs01 -DestinationComputerName NewDfs01

foreach ($each in $items) {

Set-DfsrMembership -GroupName $group -FolderName $EACH.foldername -ComputerName OldDfs01 -ContentPath $EACH.source –PrimaryMember $true -Force

}

foreach ($each in $items) {

Set-DfsrMembership -GroupName $group -FolderName $each.foldername -ComputerName NewDfs01 -ContentPath $each.Dest -Force

}
—————————————

Thanks for the help!

Richard