- function GetSCOMGroupMembers ($SCOMGrp, $DBServer, $DBCatalog)
- {
- $SqlServer = $DBServer
- $SqlCatalog = $DBCatalog
- $SCOMGroup = $SCOMGrp
- $SQLQuery = "select DisplayName from RelationShip r with (nolock)
- inner join basemanagedentity bme with (nolock) on bme.BaseManagedEntityId = R.TargetEntityId
- Where SourceEntityId in (
- select BaseManagedEntityId from basemanagedentity with (nolock)
- where DisplayName LIKE '%$SCOMGroup%')"
- $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
- $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
- $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
- $SqlCmd.CommandText = $SQLQuery
- $SqlCmd.Connection = $SqlConnection
- $SQlCmd.CommandTimeout = 120
- $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
- $SqlAdapter.SelectCommand = $SqlCmd
- $DSet = New-Object System.Data.DataSet
- $SqlAdapter.Fill($DSet) | out-null
- $SqlConnection.Close()
- $DSet.Tables[0]
- }
How to use it :
- # --------- Read the SCOMDB Server and Catalog
- $SCOMServer = "MyServer"
- $SCOMCatalog = "OperationsManager"
- # --------- Variable initialization
- $SCOMGrpName = "MyGroupName"
- # --------- Read SCOM group and get member count
- $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.
No comments:
Post a Comment