VMware Cloud Community
marvinb
Enthusiast
Enthusiast
Jump to solution

How can I list the resource associated with the output of Get-OMAlert |Get-OMRecommendaton?

I am new to PowerCli.  I've been experimenting with connectivity to vRops.

The command above lists all of the recommendations associated with the alerts, but does not have a way to output the resource it is associated with.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The ForEach statement doesn't place anything on the pipeline, that's why we store the output of the Select in a variable ($report).

After the ForEach loop completes we have everything in the variable, and can pipe it to the Export-Csv cmdlet.

Try like this

$report = foreach ($alert in Get-OMAlert) {

  Get-OMRecommendation -Alert $alert|

  Select @{N = 'Resource'; E = {$alert.Resource.Name}}, Alert, Description

}


$report | Export-CSV -Path C:\Users\blacma\Documents\powercli\output\output.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

The OMAlert object returned by Get-OMAlert contains the property Resource which is an OMResource object.

In there you find information about the resource.

You can do something like this

foreach($alert in Get-OMAlert){

   Get-OMRecommendation -Alert $alert |

  Select @{N='Resource';E={$alert.Resource.Name}},Name

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
marvinb
Enthusiast
Enthusiast
Jump to solution

This was very helpful.  I used a slight variationof this to output a few additional fields.  My problem now is that I can't seem to get the output into a file.

Whenever I try, on iteration's output seems to overwrite the last.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

How are you writing this to a file?

Can you share your code?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
marvinb
Enthusiast
Enthusiast
Jump to solution

I've tried adding export to csv to code and grid output just to see what was happening.

foreach($alert in Get-OMAlert){

Get-OMRecommendation -Alert $alert|

Select @{N='Resource';E={$alert.Resource.Name}},Alert,Description |

Export-CSV -Path C:\Users\blacma\Documents\powercli\output\output.csv}

The output only contains the information from the last iteration which I guess is to be expected.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The ForEach statement doesn't place anything on the pipeline, that's why we store the output of the Select in a variable ($report).

After the ForEach loop completes we have everything in the variable, and can pipe it to the Export-Csv cmdlet.

Try like this

$report = foreach ($alert in Get-OMAlert) {

  Get-OMRecommendation -Alert $alert|

  Select @{N = 'Resource'; E = {$alert.Resource.Name}}, Alert, Description

}


$report | Export-CSV -Path C:\Users\blacma\Documents\powercli\output\output.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
marvinb
Enthusiast
Enthusiast
Jump to solution

This fixed it and helped me better understand how things work.

0 Kudos