Greetings experts have the following script which is listing the output from the IF test only when there is output from that satisfies the IF test. If the test is not satisfied the $SCOMGroup displayname does not display. I’m looking for the values in the $SCOMGroup that are not displaying. Wondering if a try catch would be helpful here, not sure to insert a try catch into this script? Is there a way to get the try catch to write out to a file?
Next question is getting the output on the last line into a .csv file. I’ve been banging my head against the wall trying to get output to a spreadsheet but to no avail.
$SCOMGroups = (Get-SCOMGroup).Displayname
foreach ($SCOMGroup in $SCOMGroups) {
If (Get-scomgroup -Displayname $SCOMGroup| Get-SCOMClassInstance | sort Displayname | FT DisplayName) {
Write-Host “=================================================================”
Write-Host $SCOMGroup
Write-Host “=================================================================”
Get-scomgroup -Displayname $SCOMGroup | Get-SCOMClassInstance | sort DisplayName | FT DisplayName
}
}
Greetings experts:
The first sentence should read as follows:
Greetings experts have the following script which is listing the output from the IF test only when there is output which is satisfied by the IF test.
Hello Logan,
Want to first thank you for your input, it was helpful. Sorry to say still not getting the empty SCOM groups. I’m new to SCOM administration so it is a bit hard for me to explain, the problem as I see it is in the following line:
If (Get-scomgroup -Displayname $SCOMGroup| Get-SCOMClassInstance | sort Displayname | FT DisplayName).
The key is the pipe to Get-SCOMClassInstance if there are group members assigned to the group then the line list the Group and the group members (vm’s) assigned to the group. If there are no group members piping the output from Get-scomgroup to get-scomclassinstance produces nothing we might say a null value.
Your script did produce output however only a half a dozen or so groups a few were empty most were not. And as mentioned some groups that I know for a fact of have no group members did not make it to the output file.
I apologize if I wasn’t quite clear on the end goal. If you want to return the name of groups with no members use the “-ErrorAction Stop” on the Get-SCOMClassInstance.
Also, I would recommend dropping the format-table on the end. Formatting is for outputting to the console, if you are working with object in a ForEach, or a pipeline formatting them changes the type of object they are. I have updated the code I posted previously, this version is untested as I do not currently have a SCOM environment to test with, but I believe it should work as intended.
This script provides a count of the number of group members in each group. Going forward will this script in conjunction with the script in my post to clean up non-standard (default) groups in our SCOM installation.