Set-sqmDiscoveryWmiAccess
Inventory
sqmSQLTool v1.9.231+ · Set
✓ -WhatIf supported
Install-sqmDiscoveryRole covers what the scanner reads inside SQL Server. The rest of the scan (server, operating system, SQL service, ports, instances) goes through WMI and needs rights on the Windows host, which no SQL role can provide.
Per host the function handles:
Root\CIMv2 and every Root\Microsoft\SqlServer\ComputerManagement* namespace (found automatically): "Enable Account" and "Remote Enable" for the account, valid for the namespace and its sub-namespaces. "Execute Methods" is only added with -AllowExecuteMethods. Entries of other principals are left untouched. Membership in the local group Distributed COM Users (remote DCOM access). Remote Registry is only reported (state and start type), never changed: by default only Administrators and Backup Operators may reach the registry remotely.
Modes.
Check (default) reads only and changes nothing, Apply sets the rights and can be repeated, Remove takes them away again. Uses CIM cmdlets, so it runs under Windows PowerShell 5.1 and PowerShell 7. Needs local administrator rights on the target host. For a cluster instance or an AG give the node names, not the listener. Test-sqmDiscoveryAccess -CheckWmi verifies the result.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -Account | string | Required | , | The service account as DOMAIN\Name. It must resolve on the machine running the function. |
| -ComputerName | string[] | Optional | $env:COMPUTERNAME | One or more hosts. Pipeline-capable. |
| -Mode | string | Optional | Check | Check, Apply or Remove. |
| -AllowExecuteMethods | switch | Switch | $false | Additionally grants "Execute Methods". Not needed for read-only discovery. |
| -Credential | PSCredential | Optional | , | For remote hosts. Not used for the local computer. |
| -ContinueOnError | switch | Switch | $false | Continue with the next host on error. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately. |
| -WhatIf / -Confirm | switch | Optional | , | Shows each change, applies none. |
Execution Flow
Return value
One object per host with ComputerName, Account, Mode, Namespaces (namespace, access mask, required mask, Ok), DcomMember, RemoteRegistryState, RemoteRegistryStart, Changed, Ok, Status and Message.
| Status | Meaning |
|---|---|
OK | All namespaces carry the required rights and the account is in Distributed COM Users (after Remove: all of it is gone). |
Fehler | Something is missing; Message names the namespaces and the group. |
Error | The host could not be processed (for example access denied: the function needs local administrator rights). |
WhatIf | -WhatIf with Apply or Remove: nothing was changed. |
The status words Fehler and Error are the literal values the function returns. A disabled or stopped Remote Registry service is appended to Message as a hint.
Examples
Check only: what is missing on each host
Set-sqmDiscoveryWmiAccess -Account "CORP\svc_servicenow" -ComputerName SQL01, SQL02
Dry run first, then set
Set-sqmDiscoveryWmiAccess -Account "CORP\svc_servicenow" -ComputerName SQL01 -Mode Apply -WhatIf Set-sqmDiscoveryWmiAccess -Account "CORP\svc_servicenow" -ComputerName SQL01 -Mode Apply
Rollback
Set-sqmDiscoveryWmiAccess -Account "CORP\svc_servicenow" -ComputerName SQL01 -Mode Remove