Client API Cmdlets
The Glean PowerShell module exposes a set of generated cmdlets in the Glean/Public/Client directory that wrap the Glean Client API. These functions handle HTTP communication, parameter serialization, and error handling, allowing engineers to interact with Glean services such as search, collections, and verification reminders. Each cmdlet maps directly to a specific REST endpoint, accepting parameters that correspond to query strings, headers, and request bodies.
Common Architecture and Invocation Pattern
Section titled “Common Architecture and Invocation Pattern”All client cmdlets follow a consistent internal structure. They utilize a process block to construct an invocation hashtable ($__invoke) containing the API name, HTTP method, path, query parameters, headers, and body. This hashtable is then passed to the core Invoke-GleanRequest function.
Key architectural features include:
- Parameter Sets: Most cmdlets support a
Fieldsparameter set for individual arguments and aBodyparameter set for passing a raw hashtable. This allows flexibility for complexoneOf/anyOfshapes or deeply nested objects . - Internal Variables: Local variables are prefixed with
$__to prevent collisions with generated parameters, as PowerShell variable names are case-insensitive . - Headers and Query Params: Common headers like
X-Glean-ActAsandX-Glean-Auth-Typeare mapped from parameters to the request headers . TheLocaleparameter is mapped to thelocalequery string . - Retry and Raw Options: The
RetryUnsafeswitch allows non-idempotent operations to be retried on HTTP 429/503 errors [src: Glean/Public/Client/Add-GleanCollection.ps1:L28]. TheRawswitch returns the undeserialized HTTP response [src: Glean/Public/Client/Add-GleanCollection.ps1:L29].
Search and Recommendations
Section titled “Search and Recommendations”The search functionality is exposed through two main cmdlets: Find-GleanSearch and Find-GleanSearchRecommendations.
Find-GleanSearch
Section titled “Find-GleanSearch”This cmdlet wraps the Autocomplete API, retrieving query suggestions, operators, and documents for a partially typed query . It supports filtering by datasources, result types, and auth tokens for federated results . The ResultSize parameter caps the number of returned results, with a default backend cap of 200 if omitted [src: Glean/Public/Client/Find-GleanSearch.ps1:L21].
Find-GleanSearchRecommendations
Section titled “Find-GleanSearchRecommendations”This cmdlet retrieves recommended documents based on a source document or URL . It accepts parameters for PageSize and MaxSnippetSize to hint at the desired response size . It also supports TrackingToken for associating requests with previous searches [src: Glean/Public/Client/Find-GleanSearchRecommendations.ps1:L16].
Collections and Verification
Section titled “Collections and Verification”Add-GleanCollection
Section titled “Add-GleanCollection”This cmdlet adds items to a Collection . It requires a CollectionId and accepts an array of AddedCollectionItemDescriptors . The request is sent via a POST to /addcollectionitems [src: Glean/Public/Client/Add-GleanCollection.ps1:L80].
Add-GleanVerification
Section titled “Add-GleanVerification”This cmdlet creates a verification reminder for a document . It requires a DocumentId and allows specifying an Assignee, RemindInDays, and an optional Reason . The request is sent via a POST to /addverificationreminder [src: Glean/Public/Client/Add-GleanVerification.ps1:L96].