edit 07-27-2017: Updated the script with username/password variables and also dynamically determine srmserveraddr by checking the primary vcenter extension manager. This will not work if you have multiple SRM servers (ie, shared-site config)
I hit some issues finding the addfoldermapping function through the api exposed with connect-srmserver cmdlet, so I decided to use WSDL based on this post.
The main problems I encountered were that the ports changed and an issue I described in my previous post about logging into remote sites in a shared-sso domain. If you have your SRM sites in the same SSO domain, you may need to use my workaround from the previous post. I also tried to acquire SAML tokens directly, but the new-webserviceproxy doesn’t have the ability to edit SOAP headers to inject the security headers that are required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { if (Test-Path -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VMware, Inc.\VMware vSphere PowerCLI' ) { $Regkey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VMware, Inc.\VMware vSphere PowerCLI' } else { $Regkey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware vSphere PowerCLI' } . (join-path -path (Get-ItemProperty $Regkey).InstallPath -childpath 'Scripts\Initialize-PowerCLIEnvironment.ps1') } if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) { Write-Host "VMware modules not loaded/unable to load" Exit 99 } $PrimaryVC="VC1" $SecondaryVC="VC2" $username = "USER" $password = "PASS" connect-viserver $PrimaryVC $extensionmanager = get-view extensionmanager $extension = $extensionmanager.extensionlist | where-object { $_.key -eq "com.vmware.vcDR" } if($extension.count -eq 1){ #url is in format https://serverip:9086/vcdr/vmomi/sdk $srmserveraddr=$extension.server.url.split("/")[2].split(":")[0] } [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $web01 = New-WebServiceProxy("https://" + $srmServerAddr + ":9086/srm.wsdl") -Namespace SRM01 $srm01 = New-Object SRM01.Srmbinding $srm01.url = "https://" + $srmServerAddr + ":9086/vcdr/extapi/sdk" $srm01.CookieContainer = New-Object System.Net.CookieContainer $mof01 = New-Object SRM01.ManagedObjectReference $mof01.type = "SrmServiceInstance" $mof01.value = $mof01.type $srmApi01 = ($srm01.RetrieveContent($mof01)).srmApi $protection01 = ($srm01.RetrieveContent($mof01)).protection $recovery01 = ($srm01.RetrieveContent($mof01)).recovery $mapping = ($srm01.RetrieveContent($mof01)).InventoryMapping Try { $srm01.SrmLoginSites($mof01,$username, $password, $username, $password,'') } Catch [Exception] { Write-Host -BackgroundColor Red "Unable to connect to SRM $srmServerAddr" Write-Host -BackgroundColor Red $_.Exception.Message Return } Write-Host -ForegroundColor Yellow "Connected to SRM $srmServerAddr" Connect-VIServer $SecondaryVC |
Pingback: How to connect to SRM 6.1 using powershell and WSDL/SOAP - How to Code .NET
Pingback: Site Recovery Manger 6.1 addfoldermapping API and matching folders across sites | Virtual Chris