Hi All,
Our team is in need of creating roughly 600-800 groups. I have used the group.ps1 script to create a 1 group at a time, but it would great if we could get some automagic working
The objective is to have a group per building per priority . There would be potential to have 4 groups per building. I.E.
BldA P1 BldA P2 BldA P3 ...
BldB P1 BldB P2 BldB P3 ...
BldC P1 BldC P2 BldC P3 ...
... ... ... ...
My issue is I have no clue how to add the 'foreach' command into existing script, or what variables I may need to establish. I have an idea to create a csv, or txt file with the list of buildings, but past that I am unsure how to make the logic work. Here is what I am working with so far. Ideally the fields in green would be a variable that is pulled from the txt file.
==================================================================================================================================================================
$members = @(
@{ Name = "0284 - Kentucky Clinic P3"; Definition = "filter:/Orion.Nodes[CustomProperties.NetworkLayer!='UPS' AND CustomProperties.Building='0284 - Kentucky Clinic' AND CustomProperties.Priority='3']" }
)
$groupId = (Invoke-SwisVerb $swis "Orion.Container" "CreateContainer" @(
# group name
"0284 - Kentucky Clinic P3",
# owner, must be 'Core'
"Core",
# refresh frequency
60,
# Status rollup mode:
# 0 = Mixed status shows warning
# 1 = Show worst status
# 2 = Show best status
0,
# group description
"Priority 3 Nodes in 0284 - Kentucky Clinic.",
# polling enabled/disabled = true/false (in lowercase)
"true",
# group members
([xml]@(
"<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",
[string]($members |% {
"<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"
}
),
"</ArrayOfMemberDefinitionInfo>"
)).DocumentElement
)).InnerText
==================================================================================================================================================================
Suggestions/Solutions on where the foreach logic needs to be placed and formatted?
Solved! Go to Solution.
Here's the simple logic:
Create a list of all of your buildings:
$Buildings = "Building 1", "Building 2", ... "Building X"
Create a list of your priorities:
$Priorities = "P1", "P2".. "PX"
ForEach ( $Building in $Buildings )
{
Write-Host "Working on $Building"
ForEach ( $Priority in $Priorities )
{
Write-Host "Working on $Priority"
# Here's where you do the stuff in the "groups.ps1" script (basically just copy and paste it in here and then change the variables to match.
}
}
Here's the simple logic:
Create a list of all of your buildings:
$Buildings = "Building 1", "Building 2", ... "Building X"
Create a list of your priorities:
$Priorities = "P1", "P2".. "PX"
ForEach ( $Building in $Buildings )
{
Write-Host "Working on $Building"
ForEach ( $Priority in $Priorities )
{
Write-Host "Working on $Priority"
# Here's where you do the stuff in the "groups.ps1" script (basically just copy and paste it in here and then change the variables to match.
}
}
I think I may have been over thinking that. But it worked to perfection! We have over 200 buildings so a changed it up a bit. I created a txt file with our buildings had the foreach loop pull from that file. Do you see any issue with this below? It has worked for a small test at first
$Buildings = Get-Content "C:\Users\test\Desktop\Buildings.txt"
ForEach ( $Building in $Buildings )
{
Write-Host "Working on $Building"
......
Nope - from a PowerShell perspective, that's 100% fine.
SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 150,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.