Site Recovery Manger 6.1 addfoldermapping API and matching folders across sites

By | February 15, 2017

Update March 22, 2017: Added ” | Where-Object { $_.Type -eq “Folder”}” to primaryfolder.extensiondata.childentity (and the subfolder one) to filter the childentities to just folders.

SRM added a feature in which you map folder inventories across vCenters by assuming the folders had the same name and same structure. I already had one method for replicating folder structures (which I am replacing below), and was hoping to just count on the built-in matching feature of the UI. Unfortunately I found the UI to be a bit slow and new folders were not automatically mapped.

Fortunately, in 5.8 the API added the addfoldermapping method that allows you to map folders. Please note my previous post about solution users and needing to use wsdl/soap instead of powercli.

There are four functions below:

login-srmserverapi – as seen a previous post, this provides API access to SRM

copy-folderstructuretovc – replicates folder structure accurately. This function will handle multiple directories of the same name vs some other methods that assume distinct names

add-foldermapping – wrapper of call to SRM API

add-recursivefoldermapping – recurses through folder structure in primary site and looks for folder with same name at same place in tree on secondary site (handles folders with same name at different part of tree) then calls add-foldermapping as needed

I give an example below for using all of the functions below to create structure and do forward and reverse mappings.

Script add-srmfoldermappings.ps1 can also be found at Github.


3 thoughts on “Site Recovery Manger 6.1 addfoldermapping API and matching folders across sites

  1. Ken

    First of all, thanks for sharing! Exactly what I was needing. In the function copy-folderstructuretovc under create folder, I modified it to look like this:
    #create folder
    # Added if statement to avoid creating folders for each individual VM
    if ($ -like “Folder*”)
    $secondarysubfolder = New-Folder -Name $ -Location ($SecondaryFolder) -Server $global:secondaryvc -ErrorAction Stop
    Write-Host “Creating folder” $ “in” $secondaryfolder
    Without that if statement, it was creating folders named after each VM. There may be a better way to handle that, but that is what I came up with. Let me know what you think. Thanks again for sharing!

    1. Chris Post author


      I validated the issue, I was testing with an empty folder tree and didn’t realize that I would have non-folders in that array. I corrected these lines in the copy-folderstructuretovc and add-recursivefoldermapping functions:
      $primaryFolderArr = $primaryFolder.extensiondata.childentity
      $secondaryFolderArr = $secondaryFolder.extensiondata.childentity
      $primaryFolderArr = $primaryFolder.extensiondata.childentity | Where-Object { $_.Type -eq “Folder”}
      $secondaryFolderArr = $secondaryFolder.extensiondata.childentity | Where-Object { $_.Type -eq “Folder”}

      This will restrict those arrays to just folders and will be more efficient then checking the type of the object later-on (saves some unnecessary recursion).


Leave a Reply

Your email address will not be published. Required fields are marked *