Closed francescasuba closed 3 years ago
What are you trying to do? Connect to the appliance's internal database? If so thag is not possible, as the only way to get to that data (limited) is using the native Cmdlets the library provides or use the REST API natively.
No, I just want to grab the list of alerts from OneView as a PSObject and use another external module to input that PSObject into my Mongo database
To add it to my Mongo database, I need a PSObject
I am using the Mdbc Powershell module, if that helps
I'm sorry, add what exactly? What object? Please provide more context to what you are trying to do.
I see now. Your use of ConvertFrom-String is wrong here:
$finalResults = Get-OVAlert -Severity Critical -Count 10 | ConvertFrom-String
The return here would be objects, not strings. So not sure why you are doing that pipeline operation.
I have two OneView hosts, and I want to use the Get-OVAlert command for both of those hosts to pull the critical alerts. I then have to take those alerts and put it in a MongoDB.
I took ConvertFrom-String out and it's still showing the same error. It's reading those alerts as an HPEOneView.Library.Appliance.Connection
This is an issue with the target Cmdlet, not this library. You need to manually convert the objects returned from Get-OVAlert to something the target Cmdlet supports.
What is the object type of the output of Get-OVAlert function? A PSObject?
The target cmdlet supports PSObjects, which I thought Get-OVAlert returned
This was solved when I converted the object to a hashtable.
The returned object is a PSObject. One of the properties is not. It is the ApplianceConnection
property, which is a custom strongly typed class.
`Import-Module -Name HPEOneView.600
$user =
$pass = ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $pass)
$hosts =,
foreach($h in $hosts){
Connect-OVMgmt -Hostname $h -Credential $cred
$finalResults = Get-OVAlert -Severity Critical -Count 10 | ConvertFrom-String
Disconnect-OVMgmt -Hostname $h
}
$finalResults.GetType()
Connect-Mdbc -ConnectionString -DatabaseName -CollectionName "OVTest"
$Database = Get-MdbcDatabase -Name
$Collection = Get-MdbcCollection -Name "OVTest" -Database $Database
Add-MdbcData -InputObject $finalResults -Collection $Collection`
It is showing the error:
Add-MdbcData : Cannot convert 'System.Management.Automation.PSCustomObject' to 'BsonDocument'. -- Cannot convert 'HPEOneView.Library.ApplianceConnection' to 'BsonValue'.
However, when I do the PS Function GetType on $finalResults, the variable I need to input as an object, it shows as an object. But the error is saying it is an ApplianceConnection