Concept Flow - Group management
Start Script
Check if Group Exists
Add User
Confirm Action
End Script
This flow shows checking for a group, then adding a user if it exists or creating the group if it doesn't, finishing with confirmation.
if (Get-LocalGroup -Name "TestGroup" -ErrorAction SilentlyContinue) { Add-LocalGroupMember -Group "TestGroup" -Member "User1" } else { New-LocalGroup -Name "TestGroup" Add-LocalGroupMember -Group "TestGroup" -Member "User1" }
| Step | Action | Command Result | Next Step |
|---|---|---|---|
| 1 | Check if 'TestGroup' exists | Group not found (null) | Create 'TestGroup' |
| 2 | Create 'TestGroup' | Group 'TestGroup' created | Add 'User1' to 'TestGroup' |
| 3 | Add 'User1' to 'TestGroup' | 'User1' added successfully | Confirm and End |
| 4 | End Script | Script completed | Stop |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| GroupExists | null | true | true | true | true |
| GroupName | "TestGroup" | "TestGroup" | "TestGroup" | "TestGroup" | "TestGroup" |
| UserAdded | false | false | false | true | true |
Group management in PowerShell: - Use Get-LocalGroup to check group existence. - Use New-LocalGroup to create a group. - Use Add-LocalGroupMember to add users. - Always check group before adding users to avoid errors. - Script flow: Check -> Create if needed -> Add user -> Confirm.