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.
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
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
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
Get-OMRecommendation -Alert $alert |
Select @{N='Resource';E={$alert.Resource.Name}},Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
How are you writing this to a file?
Can you share your code?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
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
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
This fixed it and helped me better understand how things work.