Add SYSTEM membership check for WSS_WPG group#4
Conversation
Updated script to check for SYSTEM membership in WSS_WPG group and added error handling for group membership check.
There was a problem hiding this comment.
Pull request overview
This PR adds an early safety check to the SharePoint SE CU install helper script to detect whether the SYSTEM account (SID S-1-5-18) is a member of the local WSS_WPG group, and reports errors encountered while querying group membership.
Changes:
- Added a
Get-LocalGroupMembercheck forSYSTEMmembership inWSS_WPG. - Added a
try/catcharound the membership lookup and wrote status/error output accordingly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Write-Host "❌ SYSTEM is a member of '$GroupName'" -ForegroundColor Red | ||
| break | ||
| break | ||
| } | ||
| else { | ||
| Write-Host "✅ SYSTEM (S-1-5-18) is not a member of '$GroupName'" -ForegroundColor Green | ||
| } | ||
| } | ||
| catch { | ||
| Write-Host "❌ Error checking group membership: $($_.Exception.Message)" -ForegroundColor Red |
There was a problem hiding this comment.
All other Write-Host status messages in this script appear to be plain ASCII text; introducing emoji characters here may cause garbled output in some consoles/log pipelines and makes output harder to grep/parse consistently. Consider using a text prefix (e.g., "ERROR:" / "OK:") instead of emojis.
| Write-Host "❌ SYSTEM is a member of '$GroupName'" -ForegroundColor Red | |
| break | |
| break | |
| } | |
| else { | |
| Write-Host "✅ SYSTEM (S-1-5-18) is not a member of '$GroupName'" -ForegroundColor Green | |
| } | |
| } | |
| catch { | |
| Write-Host "❌ Error checking group membership: $($_.Exception.Message)" -ForegroundColor Red | |
| Write-Host "ERROR: SYSTEM is a member of '$GroupName'" -ForegroundColor Red | |
| break | |
| break | |
| } | |
| else { | |
| Write-Host "OK: SYSTEM (S-1-5-18) is not a member of '$GroupName'" -ForegroundColor Green | |
| } | |
| } | |
| catch { | |
| Write-Host "ERROR: Error checking group membership: $($_.Exception.Message)" -ForegroundColor Red |
| break | ||
| break |
There was a problem hiding this comment.
break is used here at script scope (not inside a loop/switch), which will throw "Cannot break outside of a loop" and prevent the script from running correctly. Use Exit (optionally with a non-zero code) or throw/return to stop execution instead, depending on desired behavior.
| break | |
| break | |
| Exit 1 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Updated script to check for SYSTEM membership in WSS_WPG group and added error handling for group membership check.