hardis:org:diagnose:underusedpermsets
Description
Command Behavior
Detects Permission Sets and Permission Set Groups that are assigned to zero users or to a configurable low number of users.
This command helps identify permission sets and permission set groups that may be candidates for cleanup or consolidation. It includes:
- Permission Sets: Custom permission sets (NamespacePrefix = null, LicenseId = null) not owned by profiles and not in groups. Excludes PSL-linked and managed package permission sets.
- Permission Set Groups: Custom groups (NamespacePrefix = null). Excludes managed package groups.
Key functionalities:
- Zero-assignment detection: Finds permission sets and groups with no assignments.
- Low-usage detection: Finds permission sets and groups assigned to
PERMSET_LIMITED_USERS_THRESHOLDor fewer users (default: 5). - Configurable threshold: Set
PERMSET_LIMITED_USERS_THRESHOLDenvironment variable to override the default (e.g.,10). - Ignore list: Set
UNDERUSED_PERMISSION_SETS_IGNOREto a comma-separated list of permission set or group names to exclude from results. - CSV Report Generation: Generates a CSV file with all identified permission sets.
- Notifications: Sends notifications to configured channels (Grafana, Slack, MS Teams).
This command is part of sfdx-hardis Monitoring and can output Grafana, Slack and MsTeams Notifications.
Technical explanations
- SOQL Queries: Uses four SOQL queries, for permission sets (zero + limited) and permission set groups (zero + limited).
- Exclusions: Permission sets in groups are excluded (counted via group); PSL-linked and managed package items are excluded.
- Ignore list:
UNDERUSED_PERMISSION_SETS_IGNOREenv var (comma-separated names) excludes matching permission sets and groups. - Report Generation: Uses
generateCsvFileto create the CSV report. - Notification Integration: Integrates with
NotifProviderfor notifications.
Agent Mode
Supports non-interactive execution with --agent:
sf hardis:org:diagnose:underusedpermsets --agent --target-org myorg@example.com
In agent mode, the command runs fully automatically. The threshold defaults to 5 (or PERMSET_LIMITED_USERS_THRESHOLD env var) when not provided.
Screenshots
Permission sets and groups of the Helios org assigned to no user, or to 5 users or fewer
- (1) One row per permission set or group, with its number of assigned users
Reports
The command writes these reports in the hardis-report folder of the project: a CSV file, and its Excel copy (XLSX) in the xls sub-folder.
Underused permission sets
One row per permission set or permission set group assigned to no user or to few users, with its user count and severity, as candidates to clean up.
Files: underused-permission-sets-*.csv, xls/underused-permission-sets-*.xlsx
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| agent | boolean | Run in non-interactive mode for agents and automation. Uses default values and skips prompts. | |||
| debug -d |
boolean | Activate debug mode (more logs) | |||
| flags-dir | option | Import flag values from a directory. | |||
| json | boolean | Format output as json. | |||
| outputfile -f |
option | Force the path and name of output report file. Must end with .csv | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| target-org -o |
option | Username or alias of the target org. Not required if the target-org configuration variable is already set. |
true | ||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:org:diagnose:underusedpermsets
$ sf hardis:org:diagnose:underusedpermsets --agent

