Changing the DSFR Staging Path with PowerShell

It took a while to figure out, but it’s totally possible to change the DFSR Staging Path programatically for any replicated folder. Here’s the scoop!

Required Reading

The Script

You’ll need to change the variables at the top.

#I want to change the stagingPath parameter of the respective instance of the DfsrReplicatedFolderConfig class
#The staging path is actually stored in AD
$computer = gc env:computername
$targetStagingPath = "G:\dfsr\staging\certdata"
$rootPathToLookFor = "*inetPub*CertData*"

#find the repl folder GUID
$ReplFolderConfigs = $null
$i = 0
While($ReplFolderConfigs -eq $null)
	{
		If($i -gt 0)
			{Sleep -seconds 2}
		ElseIf($i -gt 15)
			{
				$foundFolderConfigs = $false
				Break
			}
		$ReplFolderConfigs = gwmi -namespace "root\MicrosoftDFS" -class DfsrReplicatedFolderConfig
		$i++
	}

If(($ReplFolderConfigs.GetType().BaseType.Name) -eq "Array")
	{
		$ReplFolderConfigs | % {
			write-host -f cyan $_.RootPath
			If($_.RootPath -like $rootPathToLookFor -and $_.StagingPath -like $rootPathToLookFor)
				{$replFolder = $_}
		}
	}
Else
	{$replFolder = $ReplFolderConfigs}
$folderGUID = $ReplFolder.ReplicatedFolderGuid

write-host -f cyan "folderGuid: $folderGUID"

#grab the objet from AD
$strFilter = "(&(objectClass=msDFSR-Subscription)(CN=" + $folderGUID + "))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = $strFilter
$colResults = $objSearcher.FindAll()

If(($colResults.PSBase.GetType().Name) -eq "SearchResult")
	{$sDFSRConfigLDAPPath = $colResults.Path}
Else
	{
		$colResults | % {
			$result = $_
			$ldapResult = $result.Path
#			write-host -f green $ldapResult
			If($ldapResult -like ("*" + $computer + "*"))
				{$sDFSRConfigLDAPPath = $ldapResult}
		}
	}

#write-host -f yellow "sDFSRConfigLDAPPath: $sDFSRConfigLDAPPath"
$objDFSRConfig = [adsi]$sDFSRConfigLDAPPath

#modify the property
$stagepath = $objDFSRConfig.Get("msDFSR-StagingPath")
#write-host -f yellow "Current staging path: $stagepath"
$objDFSRConfig.Put("msDFSR-StagingPath",$targetStagingPath)
$objDFSRConfig.SetInfo()

#restart the dfsr service
Restart-Service DFSR
Sleep -seconds 10

Thanks for reading!

Advertisements

5 thoughts on “Changing the DSFR Staging Path with PowerShell

  1. Pingback: Server 2008 Enterprise Subordinate CA Install Scripts – Part 3 – DFSR | windowsmasher

  2. wonderful submit, very informative. I ponder why the other experts of this
    sector do not realize this. You should continue your writing.
    I am confident, you have a huge readers’ base already!

  3. Hello there Your site runs up really slow for my
    situation, I not really know who’s problem is that but twitter and facebook starts extremely quick.
    Anyways, I need to say thanks for adding beautiful blog post.

    Nearly everybody who found this great site should have noticed this particular article literally useful.
    This is undoubtedly terrific everything that you actually
    have done on this site and would like to discover more
    nice posts from you. I ‘ve got you book marked to check blog you publish.

  4. Hey other online sites performs perfectly for me but your site is running
    steadily which went on approximately a few minutes to be able to load up, I don’t know whether or
    not it’s my very own problem perhaps site problems.

    However , I appreciate you for creating amazing articles.

    Everyone who actually came to this great site really should have noticed this short article absolutely
    valuable. This is excellent everything that you have implemented here and
    want to check out a lot more great articles by you.
    After looking at the articles, I’ve bookmarked your web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s