Hello all
Hoping someone might be able to help me please.
According to the Documentation Centre here, you can create a report of the Protected VM's using the below script:
1. List all protection groups associated with the SRM server.
$srmApi = $srm.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
2. Generate a report of the protected virtual machines.
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
# The following command lists the virtual machines associated with a protection group
$protectedVms = $protectionGroup.ListProtectedVms()
# The result of the above call is an array of references to the virtual machines at the vSphere API
# To populate the data from the vSphere connection, call the UpdateViewData method on each virtual machine view object
$protectedVms | % { $_.Vm.UpdateViewData() }
# After the data is populated, use it to generate a report
$protectedVms | %{
$output = "" | select VmName, PgName
$output.VmName = $_.Vm.Name
$output.PgName = $protectionGroupInfo.Name
$output
}
} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }
The problem I am having is in step 1, specifically this part: $protectionGroups = $srmApi.Protection.ListProtectionGroups()
I'm using PowerCLI version VMware-PowerCLI-6.3.0-3639347, and can successfully connect-viserver and subsequently connect-srmserver works too.
The first variable of $srmApi = $srm.ExtensionData is set successfully, but the second returns the error "You cannot call a method on a null-valued expression".
Here's the exact output from the CLI session:
PowerCLI C:\> $protectionGroups = $srmApi.Protection.ListProtectionGroups()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $protectionGroups = $srmApi.Protection.ListProtectionGroups()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
PowerCLI C:\>
My end goal is to have a script that will create a list of all SRM protected VM's within the estate, but I would also like to have additional information for the VM's - like vCPU count, vRAM, hostname and OS version for example. I just can't even get over the first hurdle.
Thanks all.
Have you looked at the Get-SrmConfigReportProtectedVm function in ReportConfiguration.ps1?
Does the State property give you that?
ForEach-Object -Process {
$pg = $_
$pgInfo = $pg.GetInfo()
Get-SrmProtectedVM -ProtectionGroup $pg |
ForEach-Object -Process {
$pVm = $_
Get-VM -Name $pVm.Vm.Name |
Select @{N = "VM Name"; E = {$_.Name} },
@{N = 'State'; E = {$pVm.State}},
NumCpu, MemeoryGB,
@{N = "Protection group name"; E = {$pgInfo.Name}}
}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How do you know connect-srm works? I'm assuming $srm is the variable you capture the return from connect-srm? You should check if thats null, if so your not connected. The rest I see works and is very similar to the code I'm using for srm api calls.
Is there a specific reason why you are running this quite old version of PowerCLI?
Have a look at Welcome PowerCLI to the PowerShell Gallery – Install Process Updates how you can upgrade.
Perhaps also check the PowerShell version (with $PSVersionTable), you might want to go for 5.1 (if not already there).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi sjesse
When I run connect-viserver <server-name> -user <user>, the returned output is the server that I connected to, port and the user I specified.
I'm not specifying anything else in terms of what I want to connect to, and running connect-srmserver returns the IP address of the SRM server for the vCenter in which I initially connected, a different port, and the same user credentials.
Sorry, but I am not sure what you mean regarding the $srm variable and trying to capture the return from connect-srm?
Hi LucD
To be honest with you, its partly because of the type of environment that I am working in, but also what I was given when I requested PowerCLI to be installed.
The current SRM version is 6.1.2. I may be wrongly presuming that there is some compatibility reason for the supplied PowerCLI install vs what version of SRM is being used though. Appreciate the link - will have a look into this. I can't see the latest version due to access via the proxies, but would you happen to know if the latest version works with SRM 6.1.2 please?
My current PS version is 5.1.
Appreciate the help.
You can check the compatibility matrix for that.
And yes,it does.
In fact, the PowerCLI version you are currently using does not seem to be supported with SRM 6.1.2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks.
I've managed to get out to the internet and update PowerCLI on my machine. I had to allow clobber to get the install to work, despite attempting to uninstall PowerCLI and hoping this would be a completely fresh install. However, I'm now running the following:
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 6.7.0.1... VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-D...
Script 6.7.0.1... VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-Esx...
Manifest 11.1.0.... VMware.PowerCLI
Script 6.7.0.1... VMware.Vim
Script 11.0.0.... VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Script 11.0.0.... VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, G...
Script 11.0.0.... VMware.VimAutomation.Common
Script 11.0.0.... VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAd...
Script 7.6.0.1... VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
Script 10.0.0.... VMware.VimAutomation.License Get-LicenseDataManager
Script 11.0.0.... VMware.VimAutomation.Nsxt {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtService}
Script 11.0.0.... VMware.VimAutomation.Sdk {Get-ErrorReport, Get-InstallPath, Get-PSVersion}
Script 11.0.0.... VMware.VimAutomation.Security {Get-SecurityInfo, Get-VTpm, Get-VTpmCertificate, Get-VTpm...
Script 11.1.0.... VMware.VimAutomation.Srm {Connect-SrmServer, Disconnect-SrmServer}
Script 11.1.0.... VMware.VimAutomation.Storage {Add-KeyManagementServer, Copy-VDisk, Export-SpbmStoragePo...
Script 1.3.0.0 VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script 11.0.0.... VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, E...
Script 11.0.0.... VMware.VimAutomation.Vmc {Connect-Vmc, Disconnect-Vmc, Get-VmcSddcNetworkService, G...
Script 10.0.0.... VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-O...
Script 6.5.1.7... VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Complia...
I'm able to successfully connect-viserver, but Connect-SrmServer is throwing the following error:
PS C:\WINDOWS\system32> Connect-SrmServer
Connect-SrmServer : 14/01/2019 07:34:37 Connect-SrmServer Unable to connect to the remote server
At line:1 char:1
+ Connect-SrmServer
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-SrmServer], VimException
+ FullyQualifiedErrorId : ConnectServer_UnhandledException,VMware.VimAutomation.Srm.Commands.Commands.ConnectSrmSe
rver
I've also tried it by pointing at the SrmServerAddress with Protocol and Port switches, but it still fails to connect.
Any further help would be appreciated LucD
Cheers
Did you configure the invalid certificate action?
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah, but I set it to prompt and then set a permanent allow when prompted.
Is there any additional info in the SRM logs (files Vmware-dr-xxx log in C:\ProgramData\VMware\VMware vCenter Site Reovery Manager\Logs)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nothing jumps out at me - I can see a load of connection = true entries, but nothing to suggest my connection attempt is being denied.
Was there something you were hoping to see, or something I can search for?
I have asked for one of the network engineers to attempt to track my traffic, as I am not convinced my connection is actually getting there. Will let you know how this goes when I get a resource.
Would you know how the connections come together please? I'm going from my laptop with PowerCLI -> connect-viserver, which is self explanatory. When I try connect-srmserver, is the path PowerCLI -> SRM, or is the connection to SRM coming from the viserver I am specifying in my initial connection?
(The SRM and vCenter servers are connected to the same vSwitch so the network engineer won't be too interested in that)
As a side note, my fully qualified error is the same as this thread. I'll reply there to see if anything came of jkav's investigations.
Have a look at SRM 6 Upgrade: Not Connected to SRM Server
It contains some pointers on the connection, and also on the credentials used to authenticate.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That might have helped a lot. We do have SSO which is using AD integration at the moment. We have a change submitted to change it to LDAP. Will let you know if this makes any difference.
Additionally, Support have come back and given us this link. What I found useful were these two commands:
PowerCLI C:\> $exception = $error[0].Exception
PowerCLI C:\> $exception | select *
The above commands may help someone with their fault finding.
With the output, it looks like there is a network issue somewhere, specifically blocking 9086 to the SRM server. I thought I had checked this already, but I am working remotely at the moment, so could be VPN related. Will double check tomorrow and edit / update this post. EDIT: It was a network issue due to the remote connection, but that has been resolved and I now have a different error, which I have detailed below.
So, I'm now seeing the below:
ErrorId : ConnectServer_UnhandledException
ErrorCategory : NotSpecified
TargetObject :
RecommendedAction :
SessionId :
ConnectionId :
Severity : Error
Message : 15/01/2019 15:11:34 Connect-SrmServer Unable to connect to the remote server
Data : {ParameterValues}
InnerException : VMware.Vim.VimException: Unsupported version URI "urn:srm0/7.0"
while parsing SOAP body
at line 1, column 64
while parsing SOAP envelope
at line 1, column 0
while parsing HTTP request before method was determined
at line 1, column 0 ---> System.ServiceModel.FaultException: Unsupported version URI "urn:srm0/7.0"
while parsing SOAP body
at line 1, column 64
while parsing SOAP envelope
at line 1, column 0
while parsing HTTP request before method was determined
at line 1, column 0
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation,
ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,
ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage
retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at VMware.VimAutomation.Srm.WsdlTypes.SrmPortType.RetrieveContent(RetrieveContentRequest
request)
at VMware.VimAutomation.Srm.Views.SrmServiceInstance.RetrieveContent()
--- End of inner exception stack trace ---
at VMware.VimAutomation.Srm.Views.SrmServiceInstance.RetrieveContent()
at VMware.VimAutomation.Srm.Views.SrmClient.InitializeApiVersionForServerCalls()
at
VMware.VimAutomation.Srm.Impl.V1.SrmServiceImpl.GetAppropriateVersionClient(SrmClientConnectAction
connectAction, String hostName, String protocol, CookieContainer cookieContainer, Nullable`1 port,
IServerCertificateValidationHandler certificateValidationHandler)
at VMware.VimAutomation.Srm.Impl.V1.SrmServiceImpl.ConnectSrm(SrmClientConnectAction
connectAction, String hostName, Nullable`1 portOverride, String protocol, String username,
CookieContainer cookieContainer, IServerCertificateValidationHandler certificateValidationHandler)
at VMware.VimAutomation.Srm.Impl.V1.RelatedSrmServiceImpl.<ConnectSrmServers>d__5.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at VMware.VimAutomation.Srm.Commands.Commands.ConnectSrmServer.<>c__DisplayClass64_0.<ConnectCer
tificateValidationHandled>b__0()
TargetSite : Void ConnectCertificateValidationHandled(System.Func`2[VMware.VimAutomation.Common.Interop.V1.Certi
ficate.IServerCertificateValidationHandler,VMware.VimAutomation.Srm.Interop.V1.SrmServerInterop[]])
StackTrace : at VMware.VimAutomation.Srm.Commands.Commands.ConnectSrmServer.ConnectCertificateValidationHandl
ed(Func`2 connectAction)
at VMware.VimAutomation.Srm.Commands.Commands.ConnectSrmServer.DoWork(VIAutomation client,
List`1 moList)
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.DoWork(VIConnection connection,
List`1 moList)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.DoWorkEx(VIConnection connection,
List`1 moList)
at
VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.ExecuteRunlist(Dictionary`2
runlist, DoWorkDelegate doWorkDelegate, UidDispatchHelper uidDispatchHelper, List`1 result)
HelpLink :
Source : VMware.VimAutomation.Srm.Commands
HResult : -2146232832
You said earlier that you are using SRM 6.1.2, but the exception seems to tell different.
Or are you perhpas on a vSphere version that is not supported by this SRM version?
Check in the VMware Product Interoperability Matrices
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Strange. I've had another look at this, and logged onto the SRM servers in both sites. The version is definitely 6.1.2.
What I have found is one SRM server has 6.1.2.15007, and the other SRM server has two versions - 6.1.2.14226 and 6.1.2.15007.
Am I understanding the previous post output, indicating that SRM 7 is installed? The environment has vRealize (version 7 I am told) too.
Is there any way I can use PowerCLI to get all the versions of the environment to be totally sure?
If you can't connect, it will be difficult to get the version I'm afraid.
The alternative is to use the clients to all these products I guess.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thought you might say that. I'm going to stick with the versions I have discovered so far, and triple checked this morning. SRM is showing a build number of 6816512, and according to the Build Numbers table is version: Site Recovery Manager 6.1.2.1
Will keep digging into this, but we have a Support ticket open too, so hoping they might be able to help too.
Thanks for all your help - appreciated!
Hi,
I don't know if this is relevant here but I noticed that I had to specify credentials in order to connect to SRM in PowerCLI.
I even put together a short function to connect quickly to local and remote sites.
You probably alread know but worth mentioning that you need to be connected to vCenter beforehand.
Function Connect-SRMPair {
param( $Credentials = (Get-Credential $env:username) )Write-host “Connecting to local SRM server..” -ForegroundColor DarkCyan
if (Connect-SrmServer -Credential $Credentials) {
Write-host “Connecting to remote SRM server..” -ForegroundColor DarkCyan
$DefaultSrmServers.extensiondata.LoginRemoteSite($Credentials.username,
$Credentials.GetNetworkCredential().password,$null)
}
}
Hi LucD
I have finally managed to get SRM to connect, thanks to this thread. It looks like something is broken in version 11, and using vmware.vimautomation.srm -MaximumVersion 10.0.0.7893900 avoids the bug.
So, after running connect-srmserver, which works and shows me serviceuri, port, version, IsInUse "True" etc, i'm back to this error when running "$protectionGroups = $srmApi.Protection.ListProtectionGroups()" from the Documentation Center guide:
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $protectionGroups = $srmApi.Protection.ListProtectionGroups()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Is there something in $srmAPI?
And in $srmApi.Protection?
If there is, can you do a $srmApi.Protection | Get-Member?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference