sstranger Posted February 16, 2007 Report Share Posted February 16, 2007 First I want to say I love your software! I'm quite new to PowerShell (as most of us) but I would like to have piped the results of Alerts on my system to PowerGadget. I would like to have different colors (red for error, yellow for warning and green for information) for each column and have each column (Error, Warning, Information) in the legenda. This is the result of the PowerShell command which I want to pipe to PowerGadget. PS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::> get-alert | group-object severity | sort-object count -descending | select Count, Name Count Name ----- ---- 20 Error 6 Warning 2 Information If I pipe this to the out-chart Cmdlet from PowerGadget I don't get the result I want. Everything is in the same color and the count is in the legenda. I tried to change this by adding this: out-chart -Title "Alerts" -LegendBox_CustomItems_0_Text "Error"-LegendBox_CustomItems_0_Color Red But there must be a better way. Can you please help? Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
JuanC Posted February 16, 2007 Report Share Posted February 16, 2007 First, an explanation of the results you are getting, PowerGadgets charts will use one color per series in the chart, by default each series corresponds with a numerical column in your data so in your case there is 1 series (Count) and 3 points. There are 2 ways to get multiple colors in your chart in your scenario alerts | out-chart -datasourcesettings_style +Transpose In this case you are telling us to transpose your data, this means your chart will now have 3 series (Error, Warning, Info) and 1 Point (labeled count). Note that this would also work if you were data was returning more than 1 numerical column, e.g. Count and YesterdayCount alerts | out-chart -allseries_multiplecolors true In this case the chart still has 1 series and 3 points but you are telling us to use colors on a per-point basis instead of per-series. This approach works better when you have only one numerical column in your data. Note that in both cases the colors we choose depend on the palette, if you want to customize the colors you would do something like alerts | out-chart -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Yellow -series_2_color Green or alerts | out-chart -allseries_multiplecolors true -points_0_color Red -points_1_color Yellow -points_2_color Green One important issue in both commands, you are implicitly depending on the order of your data when assigning colors. If you can live with any ordering (e.g. Errors then Information then Warnings) then you can make your life easier by changing sort-object to sort by Name and change your colors accordingly. I am afraid we do not have a simple way of assigning colors depending on labels so one way you could achieve this would be doing this on an alternate script (alertsChart.ps1) function getColor{ if ($args[0] -eq 'Error') { return 'Red' } if ($args[0] -eq 'Warning') { return 'Yellow' } if ($args[0] -eq 'Information') { return 'Green' } return 'Black'} $items = alerts$clr0 = getColor $items[0].Name$clr1 = getColor $items[1].Name$clr2 = getColor $items[2].Name $items | out-chart -allseries_multiplecolors true -points_0_color $clr0 -points_1_color $clr1 -points_2_color $clr2Probably not the one-liner you had in mind but it gets the job done. Regards, JuanC Link to comment Share on other sites More sharing options...
sstranger Posted February 17, 2007 Author Report Share Posted February 17, 2007 Juan, Thanks your help. I solved the order of my data by sorting it by object name. If I'm correct than the first item will be Error, the next Information and the last Warning. Correct? get-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name | out-chart -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Blue -series_2_color Yellow Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
JuanC Posted February 18, 2007 Report Share Posted February 18, 2007 Yes, provided that there is no other possible name, the resulting order will be Error, Information and then Warning. Note that the script I included in my post would allow you to assign specific colors to these labels and still allow you to order them in any other way, e.g. by Count. JuanC Link to comment Share on other sites More sharing options...
sstranger Posted February 20, 2007 Author Report Share Posted February 20, 2007 Juan, Thanks for your help with the out-chart problem I had. It's working almost the way I want except for the refresh option. This is the script I've written in PowerShell to create the PowerGadget. ==================================== # Description: OpsMgr 2007 Sidebar Gadget for Remotely Retrieve OpsMgr Alerts# Date: 20-02-2007# Author: Stefan Stranger# Explanation: You can use this PowerShell script for creating a PowerGadget OpsMgr 2007 Sidebar Gadget for Vista param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$cred = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) # Add OpsMgr and PowerGadgets Cmdletsadd-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";add-pssnapin "PowerGadgets"; set-location "OperationsManagerMonitoring::"; # Connect to Root Management Server.new-managementGroupConnection -ConnectionString:$serverName -Credential (get-credential $cred); set-location $serverName; # Count the number of Alerts per Severity and refresh every minuteget-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name | out-chart -refresh 0:1:0 -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Blue -series_2_color Yellow -Title "OpsMgr 2007 Alerts" ================================== At first I get the chart I want, but after a minute I get an error "Failed to connect to Data" Does the refresh option means that the whole script is executed again? If so there is already an connection with the remote datasource and should this be disconnected? But I don't want to supply the credentials every 1 minute. Any ideas I also looked at the Get-Credential thread in the discussion forum. http://community.softwarefx.com/forums/t/9056.aspx. But I'm not sure if this is the issue I've. Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
sstranger Posted February 22, 2007 Author Report Share Posted February 22, 2007 Or is there an issue with the refresh? According to info on the forum about refresh (http://community.softwarefx.com/forums/t/9227.aspx) which states that there are issues with variables. There are some subtleties on what type of variables we support but in the simple case it will just work. But I don't use any variables on the commandline which calls the out-chart from PowerGadgets. And if I understand the refresh option correctly refresh will execute the entire PowerShell command pipe. In my case:"get-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name | out-chart -refresh 0:1:0 -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Blue -series_2_color Yellow -Title "OpsMgr 2007 Alerts"" Am I correct? So what can be the problem? Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
marco.shaw Posted February 22, 2007 Report Share Posted February 22, 2007 Perhaps you can make use of this to store the credentials: http://geekswithblogs.net/lance/archive/2007/02/16/106518.aspx Link to comment Share on other sites More sharing options...
sstranger Posted February 22, 2007 Author Report Share Posted February 22, 2007 I've created the next script. It works but haven't tested it to pipe it to out-chart. Let you know. ================# Description: OpsMgr 2007 Sidebar Gadget for Remotely Retrieve OpsMgr Alerts# Date: 22-02-2007# Author: Stefan Stranger# Version: 0.3# Explanation: You can use this PowerShell script for creating a PowerGadget OpsMgr 2007 Sidebar Gadget for Vista $serverName = "servername"$pwd = cat d:\scripts\EncryptedPwd.txt | convertto-securestring$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist "domain\account",$pwd # Add OpsMgr and PowerGadgets Cmdlets. You also use an alias "asnp"add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";add-pssnapin "PowerGadgets"; set-location "OperationsManagerMonitoring::"; # Connect to Root Management Server.new-managementGroupConnection -ConnectionString:$serverName -Credential (get-credential $cred); set-location $serverName; # Count the number of Alerts per Severity and refreshes every minuteget-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name=========================== Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
JuanC Posted February 22, 2007 Report Share Posted February 22, 2007 Your script is tricky in more than one sense so I added a blog post trying to explain some of the reasons why we may fail to refresh a script. http://community.softwarefx.com/blogs/powergadgets_team_blog/archive/2007/02/22/Writing-refreshable-scripts-for-PowerGadgets.aspx BTW, Marco was right on track on the post he deleted :-) JuanC Link to comment Share on other sites More sharing options...
sstranger Posted February 23, 2007 Author Report Share Posted February 23, 2007 Hi Juan, I'm getting there, but now I get no data available []. This is what I've done. 1. Separated the script (as suggested in your post) into to parts.2. Used arguments for servername and username. Script PromptOpsMgrAlertsChart.ps1: ===================================================param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$account = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) if (get-pssnapin | where {$_.Name -eq "PowerGadgets"}) {} else {add-pssnapin "PowerGadgets"} d:\scripts\PromptOpsMgrAlerts.ps1 -serverName $serverName -account $account | out-chart -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Blue -series_2_color Yellow -Title "OpsMgr 2007 Alerts"==================================================== And PromptOpsMgrAlerts.ps1: ====================================================# Description: OpsMgr 2007 Sidebar Gadget for Remotely Retrieve OpsMgr Alerts# Date: 20-02-2007# Author: Stefan Stranger# Explanation: You can use this PowerShell script for creating a PowerGadget OpsMgr 2007 Sidebar Gadget for Vista param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$account = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) # Add OpsMgr Cmdletsif (get-pssnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client"}) {} else {add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"} set-location "OperationsManagerMonitoring::"; # Connect to Root Management Server.new-managementGroupConnection -ConnectionString:$serverName -Credential (get-credential $account); set-location $serverName; # Count the number of Alerts per Severity and refreshes every minuteget-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name==================================================== If I run the OpsMgrAlertsChart.ps1, I'm asked for the servername and accountname. But the result is an "no data available" PowerGadget. But the refresh option seems to work. Because when I manually refresh (the no data available) PowerGadget I'm prompted again (as supposed) for the servername and username. And when refreshing again I'm not prompted for those. So that's a step in the right direction[]. But now I've to solve the "no data available" issue. I tried to change the out-chart pipe to a simple "out-chart" but that resulted in the same "no data available" Do I've to use the dataobject property? And how do I use that, because that's not completely clear to me. Any ideas? Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
JuanC Posted February 23, 2007 Report Share Posted February 23, 2007 Can you post the output you get when you run the following d:\scripts\PromptOpsMgrAlerts.ps1 -serverName ServerNameGoesHere -account AccountGoesHere Is it possible your script simply returned no alerts? JuanC Link to comment Share on other sites More sharing options...
sstranger Posted February 24, 2007 Author Report Share Posted February 24, 2007 Hi Juan, Yes it's possible that there are no alerts but that's not the case now [] Here is the output from the PromptOpsMgrAlerts.ps1 Windows PowerShellCopyright © 2006 Microsoft Corporation. All rights reserved. PS C:\Users\sstranger> d:PS D:\> cd ScriptsPS D:\Scripts> .\PromptOpsMgrAlerts.ps1 -serverName 192.168.0.3 -account "opsmgr2007demo\administrato PathName :ManagementGroup : OpsMgr DemoManagementServerName : 192.168.0.3Drives : Count Name ----- ---- 6 Error PS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::192.168.0.3> This is exactly the same result as running my first script (OpsMgr2007_SidebarGadget.ps1) that did work. But not if I added the refresh option. Result from PromptOpsMgrAlertsChart.ps1 Script: OpsMgr2007_SidebarGadget.ps1 ============================================# Description: OpsMgr 2007 Sidebar Gadget for Remotely Retrieve OpsMgr Alerts# Date: 20-02-2007# Author: Stefan Stranger# Explanation: You can use this PowerShell script for creating a PowerGadget OpsMgr 2007 Sidebar Gadget for Vista param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$cred = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) # Add OpsMgr and PowerGadgets Cmdletsadd-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";add-pssnapin "PowerGadgets"; set-location "OperationsManagerMonitoring::"; # Connect to Root Management Server.new-managementGroupConnection -ConnectionString:$serverName -Credential (get-credential $cred); set-location $serverName; # Count the number of Alerts per Severity and refreshes every minuteget-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name | out-chart -refresh 0:1:0 -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Blue -series_2_color Yellow -Title "OpsMgr 2007 Alerts"================================================ Results from above script (OpsMgr2007_SidebarGadget.ps1): PS D:\Scripts> .\OpsMgr2007_SidebarGadget.ps1Please enter your Root OpsMgr Server name: 192.168.0.3Please enter your domain\username account for accessing the Root OpsMgr Server: opsmgr2007demo\adminisAdd-PSSnapin : Cannot add Windows PowerShell snap-in Microsoft.EnterpriseManagement.OperationsManager. is already added. Verify the name of the snap-in and try again.At D:\Scripts\OpsMgr2007_SidebarGadget.ps1:10 char:13+ add-pssnapin <<<< "Microsoft.EnterpriseManagement.OperationsManager.Client";Add-PSSnapin : Cannot add Windows PowerShell snap-in PowerGadgets because it is already added. Verifynap-in and try again.At D:\Scripts\OpsMgr2007_SidebarGadget.ps1:11 char:13+ add-pssnapin <<<< "PowerGadgets"; PathName :ManagementGroup : OpsMgr DemoManagementServerName : 192.168.0.3Drives : PS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::192.168.0.3> Ignore the add-snappin errors because those were already loaded from the first script. See added images for the error after the refresh. Screenshot of the Results from the OpsMgr2007_SidebarGadget.ps1 script. Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
JuanC Posted February 24, 2007 Report Share Posted February 24, 2007 Note that your output looks like this PathName :ManagementGroup : OpsMgr DemoManagementServerName : 192.168.0.3Drives : Count Name ----- ---- 6 Error So your script is actually returning first an object with 4 properties (PathName, ManagementGroup, etc.) none of which are numbers, followed by the information you want to chart, You want your script to return just the following Count Name ----- ---- 6 Error I do not have OpsMgr installed but it seems to me the call to new-managementGroupConnection is actually returning an object. One way to work around this would be to do $obj = new-managementGroupConnection When you were running a combined script this was still happening but it did not affect you because you were only piping the get-alert to the chart, now that you are piping the script as a whole you have to be careful that your script does not return something you don't want. JuanC Link to comment Share on other sites More sharing options...
sstranger Posted February 24, 2007 Author Report Share Posted February 24, 2007 Juan, You are a hero! [Y]Thanks with all the help you gave! I've learned a lot thanks to all your great help. The refresh is now working. For all those interested here are the scripts: PromptOpsMgrAlertsChart.ps1:========================param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$account = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) if (get-pssnapin | where {$_.Name -eq "PowerGadgets"}) {} else {add-pssnapin "PowerGadgets"} d:\scripts\PromptOpsMgrAlerts.ps1 -serverName $serverName -account $account | out-chart -datasourcesettings_style +Transpose -series_0_color Red -series_1_color Blue -series_2_color Yellow -Title "OpsMgr 2007 Alerts"========================= PromptOpsMgrAlerts.ps1:=========================# Description: OpsMgr 2007 Sidebar Gadget for Remotely Retrieve OpsMgr Alerts# Date: 20-02-2007# Author: Stefan Stranger# Explanation: You can use this PowerShell script for creating a PowerGadget OpsMgr 2007 Sidebar Gadget for Vista param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$account = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) # Add OpsMgr Cmdletsif (get-pssnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client"}) {} else {add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"} set-location "OperationsManagerMonitoring::"; # Connect to Root Management Server.$obj = new-managementGroupConnection -ConnectionString:$serverName -Credential (get-credential $account); set-location $serverName; # Count the number of Alerts per Severity and refreshes every minuteget-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name================================I'll publish an article on my weblog explaining all the steps in getting this PowerGadget running. Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
sstranger Posted February 26, 2007 Author Report Share Posted February 26, 2007 Juan, I tried to use your getColor function but I've trouble getting it to work. This is what I did. (I added some debugging info) PromptOpsMgrAlertsChart2.ps1:====================param ([string]$serverName = $(read-host "Please enter your Root OpsMgr Server name"), [string]$account = $(read-host "Please enter your domain\username account for accessing the Root OpsMgr Server")) if (get-pssnapin | where {$_.Name -eq "PowerGadgets"}) {} else {add-pssnapin "PowerGadgets"} function getColor{ if ($args[0] -eq 'Error') { return 'Red' Write-host $args[0] } Write-host "Not Red" if ($args[0] -eq 'Warning') { return 'Yellow' } Write-host "Not Yellow" if ($args[0] -eq 'Information') { return 'Green' } return 'Black'} $items = d:\scripts\PromptOpsMgrAlerts.ps1 -serverName $serverName -account $account$clr0 = getColor $items[0].NameWrite-host "clr0" $clr0$clr1 = getColor $items[1].Name$clr2 = getColor $items[2].Name $items | out-chart -allseries_multiplecolors true -points_0_color $clr0 -points_1_color $clr1 -points_2_color $clr2 -Title "OpsMgr 2007 Alerts" -refresh 0:1:0========================== First I got the next error:Unable to index into an object of type System.Management.Automation.PSObject.At D:\Scripts\PromptOpsMgrAlertsChart2.ps1:31 char:25+ $clr0 = getColor $items[0 <<<< ].NameUnable to index into an object of type System.Management.Automation.PSObject.At D:\Scripts\PromptOpsMgrAlertsChart2.ps1:32 char:25+ $clr1 = getColor $items[1 <<<< ].NameUnable to index into an object of type System.Management.Automation.PSObject.At D:\Scripts\PromptOpsMgrAlertsChart2.ps1:33 char:25+ $clr2 = getColor $items[2 <<<< ].NameWARNING: -points_1_color is not a valid value for Int32. So I did a get-member. Results:PS D:\Scripts> .\PromptOpsMgrAlerts.ps1 | gm TypeName: System.Management.Automation.PSCustomObject Name MemberType Definition---- ---------- ----------Equals Method System.Boolean Equals(Object obj)GetHashCode Method System.Int32 GetHashCode()GetType Method System.Type GetType()ToString Method System.String ToString()Count NoteProperty System.Int32 Count=5Name NoteProperty System.String Name=Error Results from PromptOpsMgrAlerts.ps1.:PS D:\Scripts> .\PromptOpsMgrAlerts.ps1Please enter your Root OpsMgr Server name: 192.168.0.3Please enter your domain\username account for accessing the Root OpsMgr Server: opsmgr2007demo\administrator Count Name ----- ---- 4 Error Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
JuanC Posted February 26, 2007 Report Share Posted February 26, 2007 The getColor function along with the 3 assignments will only work if your script actually returns 3 (or more elements). In the particular test you ran, you are also hitting an issue where if your script only returns 1 item then you cannot use [ ] as your script is not returning an array of items but only that particular item. To fix this issue in your code you have 2 choices a) Prepare your chart script to handle any number of items returned by the data script, to do this change those 3 assignments so that your code can handle less items including only one or zero, note again that you may have to check first if the script actually returned a collection or just one item. Make sure your data script always returns 3 items (Error, Warning and Information). To do this I would add 3 0s to a hash indexed by a string (Error, Warning and Information), then loop through the real data replacing the appropriate items in the hash. Finally you would have to make sure you return 3 objects so that the chart (or any other cmdlet) can process them. We will keep researching if there is an easier and hopefully more general way to assign colors (and maybe other properties) based on a non-numerical property. JuanC Link to comment Share on other sites More sharing options...
sstranger Posted March 1, 2007 Author Report Share Posted March 1, 2007 Hi Juan, I tried to implement choice but it's more difficult than I thought [:@] # Count the number of Alerts per Severity and refreshes every minute#$getAlerts = get-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Name, Count$getAlerts = get-alert | group-object severity | sort-object name | select Name, Count# For the GetColor function to work the result must always return 3 items (Error, Warning and Information)$color = @{"Error"="0"; "Warning"="0"; "Information"="0"}$n=0 foreach ($i in $getAlerts) #(Error, Information, Warning) { if ($getAlerts[$n].Name -eq 'Error') { Write-host "Error exists" $n = $n + 1 } else { Write-host "Error does not exists" } if ($getAlerts[$n].Name -eq 'Information') { Write-host "Information exists" $n = $n + 1 } else { Write-host "Information does not exists" } if ($getAlerts[$n].Name -eq 'Warning') { Write-host "Warning does exists" $n = $n + 1 } else { Write-host "Warning does not exists" } if ($n -le "3") { #Write-host "test" $n = $n + 1 } } But this does not do the job. Output. PS D:\Scripts> .\PromptOpsMgrAlerts2.ps1Please enter your Root OpsMgr Server name: 192.168.0.3 Please enter your domain\username account for accessing the Root OpsMgr Server: opsmgr2007demo\administrator Error exists Information exists Warning does exists Error does not exists Information does not exists Warning does not exists Error does not exists Information does not exists Warning does not existsPS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::192.168.0.3> Better ideas? Regards,Stefan Link to comment Share on other sites More sharing options...
marco.shaw Posted March 1, 2007 Report Share Posted March 1, 2007 I think option will require that you actually create real .NET objects when there is no alerts for that particular severity. I'm short on time right now, but I think I can write something for you in the next 24 hours that might fix you up, or at least get you one or two steps ahead of where you are now... Link to comment Share on other sites More sharing options...
marco.shaw Posted March 1, 2007 Report Share Posted March 1, 2007 Try this... Take this last line from your script: # Count the number of Alerts per Severity and refreshes every minuteget-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name Change to (ignore the empty lines... darn HTML formatting): $listing=@()$listing=get-alert | where {$_.ResolutionState -eq "0"} | group-object severity | ` sort-object name | select Count, Name $states=@()$listing|%{$states+=$_.name}$levels=@("information","warning","error")foreach ($level in $levels){ if(!($states -contains $level)){ $record = new-object -typename system.object $record | add-member -membertype noteproperty -name count -value 0 [void]$foreach.movenext() $record | add-member -membertype noteproperty -name name -value $level $listing+=$record }} Now pipe $listing to out-chart. There is likely other ways to accomplish this. Give that a try and let me know... Link to comment Share on other sites More sharing options...
sstranger Posted March 1, 2007 Author Report Share Posted March 1, 2007 Marco, This is what I got when I tried your suggestion. Result: PS D:\Scripts> .\PromptOpsMgrAlerts3.ps1 Please enter your Root OpsMgr Server name: 192.168.0.3 Please enter your domain\username account for accessing the Root OpsMgr Server: opsmgr2007demo\administrator Count Name ----- ---- 5 Error Debug1 Debug2 Debug3 Debug4 Debug5 Debug6 0 0 information Debug7 Method invocation failed because [system.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'. At D:\Scripts\PromptOpsMgrAlerts3.ps1:45 char:15 + $listing+=$ <<<< record Debug8 Script: # Count the number of Alerts per Severity and refreshes every minute get-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name $listing=@() $listing=get-alert | where {$_.ResolutionState -eq "0"} | group-object severity | sort-object name | select Count, Name write-host "Debug1" $states=@() write-host "Debug2" $listing|%{$states+=$_.name} write-host "Debug3" $levels=@("information","warning","error") foreach ($level in $levels){ if(!($states -contains $level)){ $record = new-object -typename system.object write-host "Debug4" $record | add-member -membertype noteproperty -name count -value 0 write-host "Debug5" [void]$foreach.movenext() write-host "Debug6" $record $record | add-member -membertype noteproperty -name name -value $level $record write-host "Debug7" $listing+=$record write-host "Debug8" }} Regards,Stefan Link to comment Share on other sites More sharing options...
marco.shaw Posted March 1, 2007 Report Share Posted March 1, 2007 I don't know, but by looking at your post, I'm seeing extra "$record" statements, above and beyond my code sample, for example. Also from the error "op_addition" error, it doesn't seem like declaring just "$listing=@()" is doing the job for you for some reason. Maybe try "[array]$listing=@()" instead. Link to comment Share on other sites More sharing options...
sstranger Posted March 15, 2007 Author Report Share Posted March 15, 2007 It took a little longer than expected but I've published a blog about how to create an OpsMgr 2007 Alerts Sidebar Gadget. Kudo's to JuanC and Marco Shaw for their help. Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
marco.shaw Posted March 15, 2007 Report Share Posted March 15, 2007 Announce this in the 'cool scripts' forum here! Definitely a cool PowerGadget you've developed. Link to comment Share on other sites More sharing options...
sstranger Posted March 16, 2007 Author Report Share Posted March 16, 2007 Marco, I've announced it in the 'cool scripts' forum. http://community.softwarefx.com/forums/t/9105.aspx Regards,Stefan Strangerhttp://weblog.stranger.nl Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.