· Uwe Janke
Commands / Set-sqmDiscoveryWmiAccess

Set-sqmDiscoveryWmiAccess

Inventory sqmSQLTool v1.9.231+ · Set ✓ -WhatIf supported
Gives a discovery service account read-only WMI and DCOM access on SQL Server hosts. The SQL role from 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

ParameterTypeRequiredDefaultNotes
-AccountstringRequired, The service account as DOMAIN\Name. It must resolve on the machine running the function.
-ComputerNamestring[]Optional$env:COMPUTERNAMEOne or more hosts. Pipeline-capable.
-ModestringOptionalCheckCheck, Apply or Remove.
-AllowExecuteMethodsswitchSwitch$falseAdditionally grants "Execute Methods". Not needed for read-only discovery.
-CredentialPSCredentialOptional, For remote hosts. Not used for the local computer.
-ContinueOnErrorswitchSwitch$falseContinue with the next host on error.
-EnableExceptionswitchSwitch$falseThrow exceptions immediately.
-WhatIf / -ConfirmswitchOptional, Shows each change, applies none.

Execution Flow

START Resolve the account to its SID, open a CIM session per host the local computer needs no session Find the namespaces Root\CIMv2 plus every Root\Microsoft\SqlServer\ComputerManagement* on the host Mode Apply or Remove (not Check): per namespace and group Apply: set Enable Account + Remote Enable (0x21) where missing, add to Distributed COM Users Remove: drop the account's entry and the group membership; other entries stay Read the state again (always, this is the result) access mask per namespace, DCOM group membership by SID Remote Registry service: state and start type, reported only Status everything in place: OK; something missing: Fehler; -WhatIf: WhatIf Result object per host END

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.

StatusMeaning
OKAll namespaces carry the required rights and the account is in Distributed COM Users (after Remove: all of it is gone).
FehlerSomething is missing; Message names the namespaces and the group.
ErrorThe 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