From time to time I am using my PowerCli scripts to produce SRM reports. Because of this “time to time” I didn’t noticed that version 11.1.0-11289667 was distributed with broken connection to SRM servers.
Simply speaking, PowerCLI module was not able to login into SRM server, and during connection attempt, cmdlet ends up with the following error:
Connect-SrmServer : 8/29/2017 12:51:33 PM Connect-SrmServer Cannot complete login due to an incorrect user name or password.
Solution was provided in this thread: https://communities.vmware.com/message/2831641#2831641. Anyway, I did not tried this solution. Instead of this, I noticed the newer version of PowerCLI available to download: VMware-PowerCLI-11.2.0-12483598
After I had grabbed this version, it turned out that it didn’t started to work from the scratch. I had to add the following explicit argument to Connect-SrmServer cmdlet to look like this:
Connect-SrmServer -IgnoreCertificateErrors -RemoteCredential $credential -Credential $credential
Below you can find script to generate raport from total count of vm configured in SRM configuration, total CPU and MEM used by them:
Connect-VIServer -Server vCenter_SERVER
$credential = Get-Credential -Message ‘Enter Password:’ -UserName ‘domain\user’
Connect-SrmServer -IgnoreCertificateErrors -RemoteCredential $credential -Credential $credential$srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()$srmapi = $defaultsrmservers.ExtensionData
$srmpgs = $srmapi.protection.listprotectiongroups()
$srmpgsforeach ( $srmpg in $srmpgs){
foreach( $vm in $srmpg.ListProtectedVMs()){
$vms += (get-vm -id $vm.vm.MoRef)
}
}Write-Host “VMs in SRM”, $vms.Count
Write-Host “Total CPU in SRM: ” ($vms | Measure-Object numcpu -sum).sum
Write-Host “Total MEM in SRM (GB): ” ($vms | Measure-Object memorygb -sum).sum
No Comments