Create custom scom groups in bulk using script
I need to create a lot of scom groups in our new scom enviroment, and I was wondering Is there a script which reads it from a text file or something like that and then creates those groups in SCOM?
Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
August 9th, 2011 4:53pm
Well i am creating computer groups from a ini file, but it's very specific for my environment (using a dynamic query based on a registry attribute) so don't expect to find one that will fit your environment.
i've blogged about how we create groups, maybe its helpful to get you started:
http://jama00.wordpress.com/2009/12/09/creating-computergroups/
Rob Korving
http://jama00.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
August 9th, 2011 5:00pm
No, this not what I have in mind for the script. I would be great if the script reads the groups from a text (the names) and then creates them.Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
August 9th, 2011 11:25pm
I've got something like this. If anyone else is interested in seeing this, let me know and I'll queue it up and post the link.
HTH, Jonathan Almquist - MSFT
Free Windows Admin Tool Kit Click here and download it now
August 10th, 2011 1:12am
I've got something like this. If anyone else is interested in seeing this, let me know and I'll queue it up and post the link.
HTH, Jonathan Almquist - MSFT
August 10th, 2011 1:12am
you are just creating empty groups then?Rob Korving
http://jama00.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
August 10th, 2011 10:51am
I've got something like this. If anyone else is interested in seeing this, let me know and I'll queue it up and post the link.
HTH, Jonathan Almquist - MSFT
Jonathan, I'm very interested, If you could post the link that would be great.Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
August 10th, 2011 2:10pm
you are just creating empty groups then?
Rob Korving
http://jama00.wordpress.com/
Yes, indeed empty groups. We will add the servers later, these are groups where overrides are targeted against, for migrating to the new enviroment, we want to review the servers that are in the override, so we add them manually when needed, but the groups
need to be there.
Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
Free Windows Admin Tool Kit Click here and download it now
August 10th, 2011 2:10pm
you are just creating empty groups then?
Rob Korving
http://jama00.wordpress.com/
Yes, indeed empty groups. We will add the servers later, these are groups where overrides are targeted against, for migrating to the new enviroment, we want to review the servers that are in the override, so we add them manually when needed, but the groups
need to be there.
Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
August 10th, 2011 2:10pm
bump up the interest :)Scott Moss MVP (Operations Manager) | President - System Center Virtual Users Group | Vice President - Atlanta Southeast Management Users Group (ATL SMUG) Please remember to click Mark as Answer on the post that helps you!
Free Windows Admin Tool Kit Click here and download it now
August 10th, 2011 9:47pm
I will. If you do not see me respond to this in the next 7 days, bump me again. :)
BTW - good to see you're still alive and kickin, Scott. :) Keep up the great forum contibutions! Maybe see you at a future MMS???
HTH, Jonathan Almquist - MSFT
August 10th, 2011 9:58pm
I will. If you do not see me respond to this in the next 7 days, bump me again. :)
BTW - good to see you're still alive and kickin, Scott. :) Keep up the great forum contibutions! Maybe see you at a future MMS???
HTH, Jonathan Almquist - MSFT
Free Windows Admin Tool Kit Click here and download it now
August 10th, 2011 9:58pm
I'll be at MMS no doubt. Are you going to wear your Kevin Holman tee-shirt? lolScott Moss MVP (Operations Manager) | President - System Center Virtual Users Group | Vice President - Atlanta Southeast Management Users Group (ATL SMUG) Please remember to click Mark as Answer on the post that helps you!
August 15th, 2011 9:45pm
Jonathan,
How are you progressing with this script?
Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2011 11:58am
Yes Jonathan, I will second that bump-up of interest that Scott provided :-) And your 7 days are up *grin*. Thanks on behalf of the community.Bob Cornelissen - BICTT (My BICTT Blog) - Microsoft Community Contributor 2011 Recipient
August 30th, 2011 2:19pm
Thanks for the reminder! I have some time later this week, so will work on this one next. I'll post back with a link when it's up.
I never received a Holman shirt!HTH, Jonathan Almquist - MSFT
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2011 7:28pm
Jonathan, what's the progress?Certifications: MCSA 2003|MCSE 2003|MCTS(5*)| MCTIP:SA
September 5th, 2011 9:55am
This looks so promising, but I wanna confirm what variables to pop in here.
http://blog.coretech.dk/kra/automate-your-group-creation-with-powershell/
# //***************************************************************************
# // ***** Script Header *****
# //
# // Solution:
# // File: AddToGroupFromExcel.ps1
# // Author: Jakob Gottlieb Svendsen, Coretech A/S. http://www.coretech.dk
# // Purpose: Add groups from Excel sheet.
# //
# //
# // Usage: AddToGroupFromExcel.ps1
# //
# //
# // CORETECH A/S History:
# // 0.0.1 KRA 20/01/2010 Created initial version.
# // 1.0.0 JGS 26/01/2010 Created and Added logic
# // 1.0.1 JGS 27/01/2010 Added multiple group functionality
# // 1.0.2 JGS 10/02/2010 Changed to managedcomputers/servers instead of agents
# //
# // Customer History:
# //
# // ***** End Header *****
# //***************************************************************************
# //----------------------------------------------------------------------------
#//
#// Global constant and variable declarations
#/
#//----------------------------------------------------------------------------
$mpName = 'Coretech.Test' #MP you have to author?
$namespace = 'Coretech.Test' #Domain?
$opsMgrDrive = "Monitoring:\ctops.coretech.intra" #RMS?
$excelFilepath = "C:\labs\Servers.xlsx"
$col = 1 #column with servername
$row = 2 #start row
#//----------------------------------------------------------------------------
#// Main routines
#//----------------------------------------------------------------------------
#Go to OpsMgr Drive
Set-Location $opsMgrDrive -ErrorAction Stop
#Get managementpack
$mp = Get-ManagementPack -name $mpName -ErrorAction Stop
#Open excel sheet
$excel = new-object -comobject Excel.Application
$excel.visible = $false
$wb = $excel.Workbooks.Open($excelFilepath)
$end = $false
$arrMembers = $null
Write-Host "Collecting Server ID's from OpsMgr..."
#Get all agents
cd ("Monitoring:\" + (get-rootmanagementserver).Principalname)
$computers = dir
while(!$end)
{
#Read excel cell
$name = $excel.Cells.Item($row, $col).Value()
#If cell in excel is empty, assume that the list is complete
if ($name -eq $null) { $end = $true; continue; }
#Filter agents by name
$agent = $computers | where { $_.displayname -like "*$name*" }
if ($agent)
{
$group = $excel.Cells.Item($row, $col + 1).Value()
$item = New-Object System.Object
$item | Add-Member -type NoteProperty -name Name -value $agent.displayname
$item | Add-Member -type NoteProperty -name Id -value $agent.id
$item | Add-Member -type NoteProperty -name Group -value $group.toUpper()
$arrMembers += , $item
#Write-Output "Server Added: $name "
}
else #Agent not found in OpsMgr DB
{
Write-Output "Server not found: $name"
}
#Next excel row
$row++
}
#Close excel sheet
$excel.Workbooks.Close()
$excel.Quit()
#For each unique group in excel
foreach($group in ($arrMembers | Sort-Object Group | Select-Object Group -Unique))
{
$groupName = $group.group
$groupDisplayName = $group.group
#Search for exisiting group
$ExistingGroup = dir | ? { $_.PathName -eq ($namespace + "." + $group.group) }
if ($ExistingGroup)
{
Write-Host "Group Exists: $($group.group)"
do
{
$retry = $false;
$menu = Read-Host "Choose action: Delete Existing Group (D), Skip to Next Group (S), Quit Script (Q)"
switch ($menu)
{
"d" { Write-Host "Deleting Group: $($group.group)"
$mp.DeleteMonitoringObjectGroup($ExistingGroup)
$skip = $false
break; }
"s" { Write-Host "Skipping to next group"
$skip = $true
break; }
"q" { throw "Quitted script by user demand"
break; }
default { Write-Host "Invalid choice, try again"
$retry = $true }
}
} while ($retry)
}
else
{
$skip = $false
}
if (!$skip)
{
$strMembers = ""
Write-Host "Creating Group: $($group.group)"
#Add members XML
foreach ($agent in ($arrMembers | Where-Object { $_.Group -eq $group.group }))
{
Write-Host "Adding explicit member: $($agent.name) ($($agent.id))"
$strMembers += '<MembershipRule><MonitoringClass>$MPElement[Name="SystemCenter!Microsoft.SystemCenter.ManagedComputer"]$</MonitoringClass><RelationshipClass>$MPElement[Name="MicrosoftSystemCenterInstanceGroupLibrary!Microsoft.SystemCenter.InstanceGroupContainsEntities"]$</RelationshipClass><IncludeList>'
+ `
'<MonitoringObjectId>'+ $agent.ID + '</MonitoringObjectId></IncludeList></MembershipRule>'
}
$formula = $strMembers
#Write-Host $formula
#Create group
Write-Host "Saving Group: $($group.group)"
$group = New-Object Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObjectGroup($namespace,$groupName,$groupDisplayName,$formula)
$mp.InsertCustomMonitoringObjectGroup($group)
}
}
Free Windows Admin Tool Kit Click here and download it now
October 28th, 2011 10:11am


