Wednesday, February 29, 2012

[OpsMgr 2012] System Center 2012 Survival Guide

What is a survival guide? It is a page we created as a pointer to the best information on the web.  You can use the information below to learn the fundamentals; increase your current knowledge; or stay current on Operations Manager and events.  And, if you think we missed some great article out there, please add it below! 


http://social.technet.microsoft.com/wiki/contents/articles/7809.system-center-2012-operations-manager-survival-guide.aspx
The survival guide has information on

This posting is provided "AS IS" with no warranties.

Friday, February 24, 2012

[OpsMgr 2007] Export all performances rules by using a PowerShell Script

Here is a new PowerShell script usefull to list in a CSV file all performance rules in your management group - The script use a get-rules with a criteria "Category='PerformanceCollection'". Be carefull also when you developp some MPs to well categorize the rules.

$perf_collection_rules = get-rule -criteria:"Category='PerformanceCollection'"

4 functions are needed for filtering the result :

function GetPerfCounterName ([String] $configuration) {
          $config = [xml] ("<config>" + $configuration + "</config>")
          return ($config.Config.ObjectName + "\" + $config.Config.CounterName)
}


function GetFrequency ([String] $configuration) {
          $config = [xml] ("<config>" + $configuration + "</config>")
          $frequency = $config.Config.Frequency;
          if($frequency -eq $null) {
                    $frequency = $config.Config.IntervalSeconds;
          }
          return ($frequency)
}


function GetDisplayName($performanceRule) {
          if($performanceRule.DisplayName -eq $null) {
                      return ($performanceRule.Name);
           }
          else {
                      return ($performanceRule.DisplayName);
           }
}


function GetWriteActionNames($performanceRule) {
          $writeActions = "";
          foreach($writeAction in $performanceRule.WriteActionCollection) {
                     $writeActions += " " + $writeAction.Name;
           }
           return ($writeActions);
}

You are now able to export the $perf_collection_rules in a CSV file by getting the type, the rule display name, the counter name, the frequency and the write actions.

$perf_collection_rules | select-object @{name="Type";expression={foreach-object {(Get-MonitoringClass -id:$_.Target.Id).DisplayName}}},@{name="RuleDisplayName";expression={foreach-object {GetDisplayName $_}}} ,@{name="CounterName";expression={foreach-object {GetPerfCounterName $_.DataSourceCollection[0].Configuration}}},@{name="Frequency";expression={foreach-object {GetFrequency $_.DataSourceCollection[0].Configuration}}},@{name="WriteActions";expression={foreach-object {GetWriteActionNames $_}}}  | sort Type,RuleDisplayName,CounterName | export-csv "C:\perf_collection_rules.csv" -noTypeInformation


 I don't remember having developped this script by myself - perhaps it was not mine. By the way, this is very usefull.

>>>>>>>>>> Get the PS1 file Here <<<<<<<<<<

This posting is provided "AS IS" with no warranties.

Thursday, February 23, 2012

[OpsMgr 2012] Boris Yanushpolsky 's Tools updated for OpsMgr 2012 by Daniele Muscetta

First I would like to thanks Daniele and Boris for their job.

In order to not let those tools go to waste, since many people use them, Daniele Muscetta have asked Boris Yanushpolsky to give him the code of his tools and allow him to update and maintain those tools going forward.
Here is the result of Danielle's Job - the 3 tools bellow are now working with OpsMgr 2012:

Get Latest updates directly on http://blogs.msdn.com/b/dmuscett/archive/2012/02/19/boris-s-tools-updated.aspx
  • MPViewer : The previous version 1.7 (that works with OpsMgr 2007 and 2007 R2) was released here. Version 1.9 has been updated to work with OpsMgr 2012, and now includes (limited) support for MPB files (MP Bundles)

  • OverrideExplorer : The previous version 3.3 (that works with OpsMgr 2007 and 2007 R2) was released here. Version 3.4 has been updated to work with OpsMgr2012 and includes some additional, minor, fixes.

  • Proxy Settings : The previous version 1.1 (that works with OpsMgr 2007 and 2007 R2) was released here. Version 1.2 is functionally identical to the previous version but has been just recompiled to work with OpsMgr 2012 SDK.

Requirement : Operation Manager console + .NET framework 4.0 must be installed on the machine you use to run the tools

Don't hesitate to comment or report bugs to Daniele Muscetta - He will try to fix and update everything.

Remark : Just like their predecessors, it is necessary to make clear that this posting is provided "AS IS" with no warranties, and confers no rights. Use of included utilities are subject to the terms specified at http://www.microsoft.com/info/copyright.htm

This posting is provided "AS IS" with no warranties.

Monday, February 20, 2012

[OpsMgr 2007] Play with defaults settings of a management group

Here is the 2 cmdlet to know to get and set the default settings of a SCOM management group.


>>>>>>>>>>   Get-DefaultSetting   <<<<<<<<<<

NAME :     Get-DefaultSetting
SYNOPSIS :  Gets the default settings for a management group.
SYNTAX :  Get-DefaultSetting [[-Path] [<String[]>]] [<CommonParameters>]
DETAILED DESCRIPTION :  Gets the default  settings for a management group.
PARAMETERS
    -Path [<String[]>]
        Specifies the path or set of paths to the management groups for which to retrieve default settings. To enter multiple values, separate them by using commas.
    <CommonParameters>
        This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".


>>>>>>>>>>   Set-DefaultSetting   <<<<<<<<<<

NAME :     Set-DefaultSetting
SYNOPSIS :    Sets default settings.
SYNTAX :
    Set-DefaultSetting [-Name] <String> [-Value] <String> [[-Path] [<String[]>]] [-WhatIf] [-Confirm] [<CommonParameters>]
    Set-DefaultSetting [-Setting] <DefaultSettingBase[]> [[-Path] [<String[]>]] [-WhatIf] [-Confirm] [<CommonParameters>]
DETAILED DESCRIPTION :    Sets default settings.
PARAMETERS :
    -Name <String>
        Specifies the name of the default setting. The name is case-sensitive.
    -Value <String>
        Specifies the value of the default setting.
    -Path [<String[]>]
        Specifies the path or set of paths to the management groups to which to apply the default settings.
    -WhatIf
        Describes what would happen if you executed the command without actually executing the command.
    -Confirm
        Prompts you for confirmation before executing the command.
    -Setting <DefaultSettingBase[]>
        Specifies a set of default setting objects.
    <CommonParameters>
        This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".


 What are the different setting we can get and set :
  1. Agent\Heartbeats\Interval
  2. HealthService\ProxyingEnabled
  3. ManagementGroup\AlertCustomFieldSettings\CustomField1
  4. ManagementGroup\AlertCustomFieldSettings\CustomField10
  5. ManagementGroup\AlertCustomFieldSettings\CustomField2
  6. ManagementGroup\AlertCustomFieldSettings\CustomField3
  7. ManagementGroup\AlertCustomFieldSettings\CustomField4
  8. ManagementGroup\AlertCustomFieldSettings\CustomField5
  9. ManagementGroup\AlertCustomFieldSettings\CustomField6
  10. ManagementGroup\AlertCustomFieldSettings\CustomField7
  11. ManagementGroup\AlertCustomFieldSettings\CustomField8
  12. ManagementGroup\AlertCustomFieldSettings\CustomField9
  13. ManagementGroup\AlertResolution\AlertAutoResolveDays
  14. ManagementGroup\AlertResolution\HealthyAlertAutoResolveDays
  15. ManagementGroup\ClientMonitoringSettings\ErrorTransmissionFilters
  16. ManagementGroup\ClientMonitoringSettings\ExceptionFolders
  17. ManagementGroup\ClientMonitoringSettings\MaxNumberOfCabsToCollect
  18. ManagementGroup\ClientMonitoringSettings\PolicyResponseUrl
  19. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftDataCollectionRequest
  20. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftFileCollectionRequests
  21. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftMemoryDumpRequests
  22. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftRegistryCollectionRequests
  23. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftSolutionLinks
  24. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftSurveyLinks
  25. ManagementGroup\ClientMonitoringSettings\PublishMicrosoftWMIQueryRequests
  26. ManagementGroup\CustomerExperienceImprovementProgramEnabled
  27. ManagementGroup\DataWarehouse\DataWarehouseDatabaseName
  28. ManagementGroup\DataWarehouse\DataWarehouseServerName
  29. ManagementGroup\DataWarehouse\ReportingServerUrl
  30. ManagementGroup\ErrorReporting\QueueErrorReports
  31. ManagementGroup\ErrorReporting\SendErrorReports
  32. ManagementGroup\PartitioningAndGroomingSettings\AlertDaysToKeep
  33. ManagementGroup\PartitioningAndGroomingSettings\AvailabilityHistoryDaysToKeep
  34. ManagementGroup\PartitioningAndGroomingSettings\EventDaysToKeep
  35. ManagementGroup\PartitioningAndGroomingSettings\JobStatusDaysToKeep
  36. ManagementGroup\PartitioningAndGroomingSettings\MaintenanceModeHistoryDaysToKeep
  37. ManagementGroup\PartitioningAndGroomingSettings\MonitoringJobDaysToKeep
  38. ManagementGroup\PartitioningAndGroomingSettings\PerformanceDataDaysToKeep
  39. ManagementGroup\PartitioningAndGroomingSettings\PerformanceSignatureDaysToKeep
  40. ManagementGroup\PartitioningAndGroomingSettings\StateChangeEventDaysToKeep
  41. ManagementGroup\SendOperationalDataReports
  42. ManagementGroup\WebAddresses\OnlineProductKnowledge
  43. ManagementServer\AutoApproveManuallyInstalledAgents
  44. ManagementServer\MissingHeartbeatThreshold
  45. ManagementServer\ProxyAddress
  46. ManagementServer\ProxyPort
  47. ManagementServer\RejectManuallyInstalledAgents
  48. ManagementServer\UseProxyServer
  49. NotificationServer\WebAddresses\WebConsole

 --------------  EXAMPLE 1 --------------
 C:\PS>set-defaultsetting `
 -name HealthService\ProxyingEnabled `
 -value True

 This command sets the default setting agent Proxying enabled to True. Be carefull, the name of the setting is case-sensitive.

--------------  EXAMPLE 2 --------------
C:\PS>get-defaultsetting

This command gets the default settings for all connected management groups.

This posting is provided "AS IS" with no warranties.

Thursday, February 16, 2012

[Authoring MP] MPBPA analysis tool always report "Alerts should have name and description defined"

This is related to the alert configuration. You must verify that
  • when you open a rule, switch to configuration and check what is missing in the alert section.
  • If it's not there, check display name and description for the alert.
If you have separated out your strings into a language pack instead of putting the english strings into the base MP, then you will have to live with this error.
A best practice should be to have a base MP contains only the ENU strings.

This posting is provided "AS IS" with no warranties.

Friday, February 10, 2012

[OpsMgr 2007] System Center Monitoring Pack for Microsoft SQL Server 2008 R2 Parallel Data Warehouse Appliance - New Release !

Application Details

- Version:             1.0.774.0

- Release Date:     2/1/2012

 

Application Description

This Monitoring Pack for Microsoft SQL Server 2008 R2 Parallel Data Warehouse (PDW) Appliance provides capabilities to discover, monitor, and manage your SQL Server PDW appliances. The management pack simplifies the monitoring process for PDW.

In addition to health monitoring capabilities, this monitoring pack includes a custom diagram view to visualize appliance health. The custom view has detailed knowledge about the health states for the hardware and software components. The custom view enables near real-time diagnosis and resolution of detected issues.

This posting is provided "AS IS" with no warranties.

[OpsMgr 2012] Run Remote Desktop from any alert in the Console - Custom MP

I've found the post from Kevin Greene very interesting.

The aim is to enable the RDP connection from any alert within the SCOM Console irregardless of the Windows Server OS Management Pack.

The solution is to create a custom RDP task that will run independently of any management pack but with the same parameters as the 'Windows Server OS MP' RDP task.


The post http://kevingreeneitblog.blogspot.com/2012/02/scom-2012-run-remote-desktop-from-any.html also explain with screen shot the way to proceed !

Thanks to Kevin !

This posting is provided "AS IS" with no warranties.

Thursday, February 9, 2012

[Orchestrator 2012] Integration Pack 'Component Add-ons and Extensions' - Toolkit in RC now Available !

 

Files in this download

The links in this section correspond to files available for this download. Download the files appropriate for you.

File Name      Size
System_Center_2012_Orchestrator_Integration_Packs.EXE          8.0 MB     Download
System_Center_2012_Orchestrator_Integration_Toolkit_RC.EXE          2.9 MB     Download
 
 
Download the System Center 2012 Release Candidate in one convenient package as part of the Microsoft private cloud evaluation.

The following System Center 2012 - Orchestrator add-ons and extensions are available for download:

System Center 2012 Orchestrator Integration Toolkit
This toolkit contains wizard-based utilities for creating new activities and integration packs for System Center 2012 - Orchestrator . It also allows developers utilizing the Orchestrator SDK to create new custom integration packs for System Center 2012 - Orchestrator .
Features:
  • Rebranding, security enhancements, new generic activity icons
  • Wizards can upgrade 6.3 activities and IPs to be compatible with Orchestrator
  • Fixes issues with upgrading IPs multiple times
  • Fixes issues with DLL / dependent file conflicts among different IPs

System Center 2012 Orchestrator Release Candidate Integration Packs
System Center 2012 RC Orchestrator Integration Packs extend the core System Center 2012 RC Orchestrator component to enable the authoring of datacenter automation using System Center 2012 Components. Also included in this download are Integration Packs for releases of Microsoft System Center products prior to System Center 2012 RC.

This download includes Integration Packs for the following System Center 2012 RC Components:
  • System Center 2012 Virtual Machine Manager
  • System Center 2012 Operations Manager
  • System Center 2012 Data Protection Manager
  • System Center 2012 Service Manager

This download also includes Integration Packs for the following System Center product releases:
  • System Center Operations Manager 2007
  • System Center Service Manager 2010
  • System Center Virtual Machine Manager 2008
  • System Center Data Protection Manager 2010
  • System Center Configuration Manager 2007

This posting is provided "AS IS" with no warranties.

[OpsMgr 2012] Introduction to System Center Operations Manager 2012

Published: Oct 18, 2011
Updated: Jan 12, 2012
Author: Scott D. Lowe

In this article, you will learn about the new and changed elements of SCOM 2012 and discover some important prerequisites that you must understand before embarking on an installation.

This posting is provided "AS IS" with no warranties.

[SQL] Get SCOM Groups members using a SQL Query on OperationsManager DB

Here is a short query that is very usefull to list all member of a SCOM group. Use it on your OperationsManager DB :
  1. select DisplayName from RelationShip r with (nolock)
  2. inner join basemanagedentity bme with (nolock) on bme.BaseManagedEntityId = R.TargetEntityId
  3. Where SourceEntityId in (
  4.             select BaseManagedEntityId from basemanagedentity with (nolock)
  5.             where DisplayName LIKE '%GroupName%')
  6. Order by DisplayName

This posting is provided "AS IS" with no warranties.

Opalis Integration Server & System Center Operations Manager Extensibility Kit 2.0

source code, 12K, uploaded Nov 5 2010
documentation, 1020K, uploaded Nov 5 2010
 
Please refer to http://opalis.codeplex.com/releases/view/50751 - original post where I've found the information
 
The Opalis Integration Server (OIS) – System Center Operations Manager (SCOM) Extensibility Kit 2.0 includes examples of how to extend SCOM using both the SCOM and OIS SDKs. The C# code and compiled DLL included here offer two OIS objects which can be used to automatically create or delete notification subscriptions based on an existing Channel as well as work against existing Pending Agent Installs in the SCOM database.

Included in this Extensibility Kit:
  • Opalis Ready DLL:
  • Can be used with the “Invoke .NET” object included in the Integration Pack for “Opalis Quick Integration Kit for Microsoft .NET”
    • OpalisSCOMExtensibility.dll
    • NOTE: This DLL is dependent on some other resources, see System Requirements.
  • C# Source Code:
  • Example C# Source Code illustrating the combination of the SCOM and OIS SDKs.
    • SCOM_NoteSubcriptionCreate.cs
    • SCOM_NoteSubcriptionDelete.cs
    • SCOM_AgentInfoAdapter.cs
    • SCOM_ApprovePendingAgentInstall.cs
    • SCOM_ListPendingAgentInstalls.cs
    • NOTE: These C# files are dependent on some other resources, see System Requirements.

This Extensibility Kit (DLL to be used with the Opalis “Invoke .NET” object) adds the following object capability to Opalis Integration Server:
  • Create SCOM Notification Subscription (SCOM.SCOMSDK.SCOMNoteSubcriptionCreate)
  • Delete SCOM Notification Subscription (SCOM.SCOMSDK.SCOMNoteSubcriptionDelete)
  • List Pending Agent Installs (SCOM.SCOMSDK.SCOMListPendingAgentInstalls)
  • Approve Pending Agent Installs (SCOM.SCOMSDK.SCOMApprovePendingAgentInstall)

This DLL (and appropriate dependencies) can be rolled up into an Opalis Integration Pack (not included here) by using the QIK Wizard.

Please Refer to the OIS-SCOM Extensibility Kit 2.0 - User Guide for more information on System Requirements, Installation, Configuraiton and Usage.

This posting is provided "AS IS" with no warranties.

Friday, February 3, 2012

[SCOM 2007] Operations Manager Dynamic Group Examples by Jeanie Decker (Microsoft)

Please find on this page an article that provides example of group definitions. The examples describe the items to select in the Query Builder and the resulting formula.


First published by

This posting is provided "AS IS" with no warranties.

Wednesday, February 1, 2012

[Powershell] Playing with registry keys in powershell

I've had to read and write some registry keys from my management pack to implement a functionnality for debugging purpose - all events are created in in the Operations Manager Event log.

Here are the differents functions that can be usefull :
  • CheckIfRegistryKeyExists : create event 200 (Information or Error) depending of the result
  • ReadRegistryKey : Read the key value and write information event 200
  • WriteRegistryKey : Write the key value and write information event 200
  • Write-ErrorInfo : create error event 500
  • Write-DebugInfo : create Information event 100

Copy the code below in a  ReadRegistryKey.ps1 file for example

  1. param ($RegistryKeyPath, $KeyName, $KeyValue, $Debug)
  2. if ($debug -ne "true"){$debug = [bool]$false}else{$debug = [bool]$true}
  3. $Script:API             = new-object -comObject "MOM.ScriptAPI"
  4. $Script:Bag             = $Script:API.CreatePropertyBag()
  5. $Script:LOG_ERROR       = 1
  6. $Script:LOG_WARNING     = 2
  7. $Script:LOG_INFORMATION = 4
  8. $Script:ScriptName      = "ReadRegistryKey.ps1"
  9. $Script:Arguments       = "Received Arguments:`RegistryKeyPAth = $RegistryKeyPath `rKeyName = $KeyName `rDebug = $debug"
  10. #------------------------------------------------------------------------------------------
  11. Function CheckIfRegistryKeyExists($KeyPath,$KeyName)
  12. {
  13.  $KeytoRead = $KeyPath
  14.  $KeytoReadName = $KeyName
  15.  $a = (Get-ItemProperty -path registry::$KeytoRead).$KeytoReadName -eq $null
  16.  if ($a -eq "false")
  17.   {
  18.   $Script:API.LogScriptEvent("CheckIfRegictyryKeyExists",200,$Script:LOG_ERROR,"`r$KeyPath\$KeyName doesn't exist !")
  19.   }
  20.  else
  21.   {
  22.   $Script:API.LogScriptEvent("CheckIfRegictyryKeyExists",200,$Script:LOG_INFORMATION,"`r$KeyPath\$KeyName exists.")
  23.   }
  24. }
  25. #------------------------------------------------------------------------------------------
  26. function ReadRegistryKey($KeyPath,$KeyName)
  27. {
  28.     $Script:API.LogScriptEvent("$ScriptName",200,$Script:LOG_INFORMATION,"`r$KeyPath\$KeyName ")
  29.  $KeytoRead = $KeyPath
  30.  $KeytoReadValue = $KeyName
  31.  $a = Get-ItemProperty -path registry::$KeytoRead -name $KeytoReadValue
  32.  $ReadValue = $a.$KeytoReadValue
  33.  $ReadValue
  34. }
  35. #------------------------------------------------------------------------------------------
  36. function WriteRegistryKey($KeyPath,$KeyName,$KeyValue)
  37. {
  38.  $Script:API.LogScriptEvent("$ScriptName",200,$Script:LOG_INFORMATION,"`r$KeyPath\$KeyName with value $KeyValue is created")
  39.  $KeytoRead = $KeyPath
  40.  $KeytoReadValue = $KeyName
  41.  $Value = $KeyValue
  42.  $a = Set-ItemProperty -path registry::$KeytoRead -name $KeytoReadValue -Value $Value
  43.  $a.$KeytoReadValue
  44. }
  45. #------------------------------------------------------------------------------------------
  46. function Write-DebugInfo([string] $msg)
  47. {
  48.     if ($debug)
  49.     {
  50.         $Script:API.LogScriptEvent("$ScriptName",100,$Script:LOG_INFORMATION,"`r$Arguments`r`r$msg")
  51.     }
  52. }
  53. #------------------------------------------------------------------------------------------
  54. function Write-ErrorInfo([string] $msg)
  55. {
  56.     if ($debug)
  57.     {
  58.     $Script:API.LogScriptEvent("$ScriptName",500,$Script:LOG_ERROR,"`r$Arguments`r`r$msg")
  59.  }
  60. }
  61. #------------------------------------------------------------------------------------------
  62. # MAIN CODE START HERE
  63. #------------------------------------------------------------------------------------------
  64. # Use this line to Read the registry key
  65. ReadRegistryKey $RegistryKeyPath $KeyName
  66. # Use this line to Create the registry key with its value
  67. WriteRegistryKey $RegistryKeyPath $KeyName $KeyValue
  68. # Use this line to check if key exist
  69. CheckIfRegistryKeyExists $RegistryKeyPath $KeyName
Then is a powershell command shell, just launch the ReadRegistryKey.ps1 with the parameters like :
> C:\scripts\ReadRegistryKey.ps1 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\
Microsoft Operations Manager\Debugging" "ForTestingPurpose" "ValueToSet" "true"

When the HKLM\SOFTWARE\Microsoft\Microsoft Operations Manager\Debugging\ForTestingPurpose key doens't exist :
  • ReadRegistryKey function will return
Case : key tested exists :

Case key doens't exist : To be implemented since the code return error in powershell or just use the CheckRegistryKey function before.

Get-ItemProperty : Property ForTestingPurpose1 does not exist at path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Operations Manager\Debugging.
At C:\scripts\ReadRegistryKey.ps1:35 char:23
+     $a = Get-ItemProperty  <<<< -path registry::$KeytoRead -name $KeytoReadValue

  • Write registry key will create the key and return :

  • Checking the registry key can return 2 states :
Key doens't exist


And also Key exists :


 Hope this will be helpful.





This posting is provided "AS IS" with no warranties.

[Powershell] Delete .log file older than 1 month in a specified folder

Here is a short script that will help you to clean a folder that contains .log files that have a creation date older than one month. The function can use an argument to be verbose or not - Verbose mode write events in the Operations Manager Event Log when it's launched by SCOM.

Save this few line in a DeleteOldLogs.ps1 file.
  1. param ($FolderPath, $Debug)
  2. if ($debug -ne "true"){$debug = [bool]$false}else{$debug = [bool]$true}
  3. $Script:API             = new-object -comObject "MOM.ScriptAPI"
  4. $Script:Bag             = $Script:API.CreatePropertyBag()
  5. $Script:LOG_ERROR       = 1
  6. $Script:LOG_WARNING     = 2
  7. $Script:LOG_INFORMATION = 4
  8. $Script:ScriptName      = "DeleteOldLogs.ps1"
  9. $Script:Arguments       = "Received Arguments:`FolderPath = $FolderPath `rDebug = $debug"
  10. function Write-DebugInfo([string] $msg)
  11. {
  12.     if ($debug)
  13.     {
  14.         $Script:API.LogScriptEvent("$ScriptName",100,$Script:LOG_INFORMATION,"`r$Arguments`r`r$msg")
  15.     }
  16. }
  17. function Write-ErrorInfo([string] $msg)
  18. {
  19.     $Script:API.LogScriptEvent("$ScriptName",500,$Script:LOG_ERROR,"`r$Arguments`r`r$msg")
  20. }
  21. $date= (get-date).AddMonths(-1)
  22. $Files = get-childitem -Path $FolderPath -include *.log -recurse | Where-Object {$_.CreationTime -lt $date}
  23. foreach ($File in $Files)
  24. {
  25.  if ($File) {
  26.  Write-DebugInfo "Deleting File '$File'"
  27.  Remove-Item $File | out-null
  28. }
  29. }

 In the powershell command shell, just launch
> DeleteOldLogs.PS1 "C:\temp" "true"

This posting is provided "AS IS" with no warranties.

[Powershell] Query Database by using a powershell function

Here is a usefull function to query a DB from a powershell script.

  1. function RunQueryOnDB ($DBServer, $DBCatalog, $DBQuery, $DBUid, $DBUidPWD)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SqlQuery = $DBQuery
  6. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  7. $SqlConnection.ConnectionString = "Server = $SqlServer; Database = $SqlCatalog; Uid = $DBUid; Pwd = $DBUidPWD"
  8. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  9. $SqlCmd.CommandText = $SqlQuery
  10. $SqlCmd.Connection = $SqlConnection
  11. $SQlCmd.CommandTimeout = 120
  12. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  13. $SqlAdapter.SelectCommand = $SqlCmd
  14. $DSet = New-Object System.Data.DataSet
  15. $SqlAdapter.Fill($DSet) | out-null
  16. $SqlConnection.Close()
  17. $DSet.Tables[0]
  18. }

How to use it :
  1. # --------- set the DB Server and Catalog
  2. $DBServerName = "MyDBServer"
  3. $DBName = "MyDBNAme"
  4. # --------- Set the Query
  5. $Query = "Select PrincipalName from MyDB"
  6. # --------- Set the credentials to use to query the DB
  7. $Account = "MyAccount"
  8. $pwd = "MyPassword"
  9. # --------- Variable initialization
  10. $SCOMGrpName = "MyGroupName" 
  11. # --------- Query The DB
  12. $Result = RunQueryOnDB $DBServerName $DBName $Query $Account $pwd
The script wil return a table $Result that can also be re-used.

This posting is provided "AS IS" with no warranties.

[Powershell] Get SCOM Groups members using a SQL Query

Here is a new powershell script that I had to use to develop MPs. Retieving SCOM Groups members (displayName in the exemple)by using the SCOM DB.
  1. function GetSCOMGroupMembers ($SCOMGrp, $DBServer, $DBCatalog)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SCOMGroup = $SCOMGrp
  6. $SQLQuery = "select DisplayName from RelationShip r with (nolock)
  7. inner join basemanagedentity bme  with (nolock) on bme.BaseManagedEntityId = R.TargetEntityId
  8. Where SourceEntityId in (
  9. select BaseManagedEntityId from basemanagedentity with (nolock)
  10. where DisplayName LIKE '%$SCOMGroup%')"
  11. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  12. $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
  13. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  14. $SqlCmd.CommandText = $SQLQuery
  15. $SqlCmd.Connection = $SqlConnection
  16. $SQlCmd.CommandTimeout = 120
  17. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  18. $SqlAdapter.SelectCommand = $SqlCmd
  19. $DSet = New-Object System.Data.DataSet
  20. $SqlAdapter.Fill($DSet) | out-null
  21. $SqlConnection.Close()
  22. $DSet.Tables[0]
  23. }

How to use it :
  1. # --------- Read the SCOMDB Server and Catalog
  2. $SCOMServer = "MyServer"
  3. $SCOMCatalog = "OperationsManager" 
  4. # --------- Variable initialization
  5. $SCOMGrpName = "MyGroupName" 
  6.  # --------- Read SCOM group and get member count
  7. $GroupMembersList = GetScomGroupMembers $SCOMGrpName $SCOMServer $SCOMCatalog
The script wil return a table $GroupMembersList that can also be re-used.

This posting is provided "AS IS" with no warranties.

[Powershell] Get SCOM Groups using a SQL Query

Today, I'll add a new powershell script that I had to use for a developped MP. Retieving SCOM Groups by using the SCOM DB.
  1. Function GetSCOMGroupsInSQL ($DBServer, $DBCatalog)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SQLQuery = "select distinct SCOMGroup = convert(varchar(100), upper(rtrim(ltrim(BME.Displayname))))"
  6. $SQLQuery += " from BaseManagedEntity BME"
  7. $SQLQuery += " left join dbo.ManagedTypeView T1 on (BME.BaseManagedEntityId = T1.Id)"
  8. $SQLQuery += " Left join dbo.Relationship R1 on(BME.BaseManagedEntityId=R1.Sourceentityid)"
  9. $SQLQuery += " left join BaseManagedEntity ME2 on (ME2.BaseManagedEntityId=R1.targetentityid)"
  10. $SQLQuery += " left join dbo.ManagedTypeView T2 on(ME2.BaseManagedEntityId=T2.id)"
  11. $SQLQuery += " where (T1.Name like 'UINameSpace%.Group' or T1.Name like '%MySpecificGroupName%')"
  12. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  13. $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
  14. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  15. $SqlCmd.CommandText = $SqlQuery
  16. $SqlCmd.Connection = $SqlConnection
  17. $SQlCmd.CommandTimeout = 120
  18. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  19. $SqlAdapter.SelectCommand = $SqlCmd
  20. $DSet = New-Object System.Data.DataSet
  21. $SqlAdapter.Fill($DSet) | out-null
  22. $SqlConnection.Close()
  23. $DSet.Tables[0]
  24. }
How to use it :
  1. # --------- Read the SCOMDB Server and Catalog
  2. $SCOMServer = $Config.Groups.SCOMDB.SCOMDBServerName
  3. $SCOMCatalog = $Config.Groups.SCOMDB.SCOMDBName
  4. # --------- Query SCOM DB to get Agent list and Group List
  5. $GroupList = GetSCOMGroupsInSQL $SCOMServer $SCOMCatalog
The script wil return a table $GroupList that can also be re-used.

This posting is provided "AS IS" with no warranties.

[Powershell] Get SCOM Agents using a SQL Query

Today, I'll add a new powershell script that I had to use for a developped MP. Retieving SCOM agents by using the SCOM DB instead of Get-Agent cmdlet.
The aim was to have a very fast answer of the script and using the Get-Agent cmdlet was really too long.

  1. Function GetSCOMAgentsInSQL ($DBServer, $DBCatalog)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SQLQuery =  "SELECT distinct(B.displayname)"
  6. $SQLQuery += " FROM TypedManagedEntity T WITH(NOLOCK)"
  7. $SQLQuery += " JOIN BaseManagedEntity B WITH(NOLOCK)    ON B.BaseManagedEntityId = T.BaseManagedEntityId"
  8. $SQLQuery += " WHERE T.ManagedTypeId = dbo.fn_ManagedTypeId_MicrosoftSystemCenterAgent()"
  9. $SQLQuery += " order by 1"
  10. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  11. $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
  12. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  13. $SqlCmd.CommandText = $SqlQuery
  14. $SqlCmd.Connection = $SqlConnection
  15. $SQlCmd.CommandTimeout = 120
  16. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  17. $SqlAdapter.SelectCommand = $SqlCmd
  18. $DSet = New-Object System.Data.DataSet
  19. $SqlAdapter.Fill($DSet) | out-null
  20. $SqlConnection.Close()
  21. $DSet.Tables[0]
  22. }

How to use it :
  1. # --------- Read the SCOMDB Server and Catalog
  2. $SCOMServer = $Config.Groups.SCOMDB.SCOMDBServerName
  3. $SCOMCatalog = $Config.Groups.SCOMDB.SCOMDBName
  4. # --------- Query SCOM DB to get Agent list and Group List
  5. $AgentList = GetSCOMAgentsInSQL $SCOMServer $SCOMCatalog
The script wil return a table $AgentList that can also be re-used.

This posting is provided "AS IS" with no warranties.

[SCOM 2007] Overrides report per server

The reports provided with System Center Operations Manager 2007 may sometimes seem particularly poor in terms of daily operations on the product. Today, Jean-Sébastien Dûchene offers a report which lists all the overrides that have been created and applied to a given machine.

French and English page is available here :


This includes targeting overrides:
  • entities (disk, database ...) attached,
  • groups with the machine or its entities are part
  • class
 
You can then retrieve information such as the Management Pack, the type (Monitor/rule), the name of the rule or the monitor, the type of context, the target name, the setting overrided, the value, the value of Enforced option, the last modified date, the added date, or the management pack used to store the change.

 Note that :
  • The report can be long to run.
  • Do not necessarily reflect the actual configuration on the client since you can have several different values overrided affecting a class, group, and object.
Do not forget to create a datasource targeting to the operational database with security rights necessary to generate the report.

 
Thanks to Jean-Sébastien Dûchene - This report is provided "AS IS" without express or implied warranty of any kind.


This posting is provided "AS IS" with no warranties.