Skip to content

hardis:org:diagnose:licenses

Description

Lists and analyzes User Licenses and Permission Set Licenses subscribed and used in a Salesforce org.

This command provides a comprehensive overview of your Salesforce license consumption. It's particularly useful for:

  • License Management: Understanding which licenses are active, how many are available, and how many are being used.
  • Cost Optimization: Identifying unused or underutilized licenses that could be reallocated or decommissioned.
  • Compliance: Ensuring that your organization is compliant with Salesforce licensing agreements.
  • Monitoring: Tracking license usage trends over time.

Key functionalities:

  • User License Details: Retrieves information about standard and custom User Licenses, including MasterLabel, Name, TotalLicenses, and UsedLicenses.
  • Permission Set License Details: Retrieves information about Permission Set Licenses, including MasterLabel, PermissionSetLicenseKey, TotalLicenses, and UsedLicenses.
  • Used Licenses Filter: The --usedonly flag allows you to filter the report to show only licenses that have at least one UsedLicenses count greater than zero.
  • CSV Report Generation: Generates a CSV file containing all the retrieved license information, suitable for detailed analysis.
  • Notifications: Sends notifications to configured channels (e.g., Grafana, Slack, MS Teams) with a summary of license usage, including lists of active and used licenses.
Technical explanations

The command's technical implementation involves:

  • Salesforce SOQL Queries: It executes SOQL queries against the UserLicense and PermissionSetLicense objects in Salesforce to retrieve license data.
  • Data Transformation: It processes the query results, reformatting the data to be more readable and consistent for reporting purposes (e.g., removing Id and attributes, renaming PermissionSetLicenseKey to Name).
  • Data Aggregation: It aggregates license information, creating a licensesByKey object for quick lookups and a usedLicenses array for a concise list of actively used licenses.
  • Report Generation: It uses generateCsvFile to create the CSV report of license data.
  • Notification Integration: It integrates with the NotifProvider to send notifications, including attachments of the generated CSV report and metrics for monitoring dashboards.
  • User Feedback: Provides clear messages to the user about the license extraction process and the used licenses.

Agent Mode

Supports non-interactive execution with --agent:

sf hardis:org:diagnose:licenses --agent --target-org myorg@example.com

In agent mode, the command runs fully automatically with no interactive prompts.

Screenshots

The licenses of the org, with the report buttons at the end of the run

The licenses of the org, with the report buttons at the end of the run

  • (1) The report of the run: the button opens it in Excel, the arrow lists its other files

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.

Licenses

One row per license of the org (user licenses, permission set licenses), with the number of licenses bought and used.

Files: licenses-*.csv, xls/licenses-*.xlsx

Licenses report in Excel

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
usedonly
-u
boolean Filter to have only used licenses
websocket option Websocket host:port for VsCode SFDX Hardis UI integration

Examples

$ sf hardis:org:diagnose:licenses
$ sf hardis:org:diagnose:licenses --agent

Comments