Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 175326

Unable to import alarms from a deserialized xml object(ouput from Export-Clixml)

$
0
0

Hi,

I  have tried and modified the script according to my requirement given by Angel in Re: Script to export/import Alarms between VC or synchronize alarms between 2 Virtual Centers

Actually, in Angel's script for each alarm there will be a .xml file created in the folder. But, I tried script like
appending all the alarms info to a single xml file as below:

 

function ExportAlarm(){
    Connect-VIServer $serverToExportFrom -User 'xxxx'-Password 'xxxx'
    $alarmToExport = Get-AlarmDefinition -Entity (Get-Folder -NoRecursion) -Name
    $xml= @()
    foreach ($alarm in $alarmToExport)
    {
    $a = Get-View -Id $alarm.Id
    $xml += $a.Info
    }
    $xml | Export-Clixml -Path $fileName -Depth ( [System.Int32]::MaxValue )
}

 

I am able to collect all the alarms info in a single xml file. But while importing the xml file with import function like below:

 

function ImportAlarm {

Connect-VIServer $serverToImportTo -User 'xxxx'-Password 'xxxx'
$deserializedAlarmInfo = Import-Clixml -Path $fileName
$importedAlarmInfo = ConvertFromDeserialized( $deserializedAlarmInfo )
$entity = Get-Folder -NoRecursion
$alarmManager = Get-View -Id "AlarmManager"
$alarmManager.CreateAlarm($entity.Id, $importedAlarmInfo)
}

 

I did not edit the ConvertFromDeserialized function.While importing, I am getting an error saying

 

Exception calling "SetValue" with "3" argument(s): "Object of type 'System.Object[]' cannot be converted to type 'System.String'."
At C:\Nag\requests\req4add-delete-modify-Alarms\newreq\newreqimporttest.ps1:59 char:6
+                     $resultProperty.SetValue($result, $propertyValue, $null)
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

Exception calling "CreateAlarm" with "2" argument(s): "
Required property name is missing from data object of type AlarmInfo
while parsing serialized DataObject of type vim.alarm.AlarmInfo
at line 1, column 335
while parsing call information for method CreateAlarm
at line 1, column 218
while parsing SOAP body
at line 1, column 207
while parsing SOAP envelope
at line 1, column 38
while parsing HTTP request for method create
on object of type vim.alarm.AlarmManager
at line 1, column 0"
At C:\Nag\requests\req4add-delete-modify-Alarms\newreq\newreqimporttest.ps1:10 char:2
+     $alarmManager.CreateAlarm($entity.Id, $importedAlarmInfo)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException

 

Please find the complete error in the attachment.

Could you please guide me on how to export/import all alarms to/from a single xml file rather than a folder having xml file for each alarm. If there are any limitations, please let me know. Thanks a lot for all your help.


Viewing all articles
Browse latest Browse all 175326

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>