# Extension V2 status code errors

**URL:** <https://community.dynatrace.com/t/extension-v2-status-code-errors/40946>\
**Category:** Extensions\
**Tags:** extensions\
**Created:** [July 31, 2023, 5:35pm UTC](https://community.dynatrace.com/t/extension-v2-status-code-errors/40946 "2023-07-31T17:35:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [July 31, 2023, 5:35pm UTC](https://community.dynatrace.com/t/extension-v2-status-code-errors/40946/1 "2023-07-31T17:35:15Z")

</div>

When using the WMI extension, I’m getting in the logs the following two types of logs, for some entries:

- DEVICE\_CONNECTION\_ERROR:Cannot connect to the server on device MachineA : Exception occurred. (The RPC server is unavailable. ) [status code=38];
- DEVICE\_CONNECTION\_ERROR:Cannot execute query: Adapters on device MachineB: Exception occurred. (Invalid class ) [status code=38];

What does the status\_code 38 mean? I’m aware of a Product Idea for this: [https://community.dynatrace.com/t5/Product-ideas/Extension-2-0-Convert-a-status-code-into-a-meaningful-text/idi-p/181283](https://community.dynatrace.com/post/181283)

but in the meantime, is there some resource where we can lookup these error codes?

---

<div class="post-metadata">

**Author:** ![jegron](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jegron/32/12797_2.png) [@jegron](https://community.dynatrace.com/u/jegron)\
**Post date:** [August 2, 2023, 8:29am UTC](https://community.dynatrace.com/t/extension-v2-status-code-errors/40946/2 "2023-08-02T08:29:57Z")

</div>

Hi [@AntonioSousa](https://community.dynatrace.com/user/17213) ,

I’ve encountered these errors many times. Most of time Remote WMI prerequisites was missing.

I built a PowerShell script to avoid human errors with prerequisites ([WMI data source — Dynatrace Docs](https://www.dynatrace.com/support/help/extend-dynatrace/extensions20/data-sources/wmi-extensions)). My use case was for a local account but you adapt it to a domain account.

Main script :

```markup
# Create account
$userName = "YourUsername"
$password = "YourPassword"
[SecureString]$securepassword = $password | ConvertTo-SecureString -AsPlainText -Force 
New-LocalUser -Name $userName -Description "YourUsername" -Password $securepassword -PasswordNeverExpires
Get-LocalUser

# Add to "Distributed COM Users"
Add-LocalGroupMember -SID "S-1-5-32-562" -Member "YourUsername"
# Add to "Performance Monitor User Group"
Add-LocalGroupMember -SID "S-1-5-32-558" -Member "YourUsername"

# Access right Remote WMI
& $PSScriptRoot\Set-WmiNamespaceSecurity.ps1 root/cimv2 -operation add -account YourUsername Enable,RemoteAccess

# Disable Remote UAC (if device not in a domain)
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name LocalAccountTokenFilterPolicy -PropertyType DWord -Value 1 -Force

# Open Firewall
$Params = @{
	"Group" = '@FirewallAPI.dll,-34251'
	"Action" = 'Allow'
	"Enabled" = 'True'
}
Set-NetFirewallRule @Params​​

```

Set-WmiNamespaceSecurity.ps1 :

```markup
# Copyright (c) Microsoft Corporation. All rights reserved. 
# For personal use only. Provided AS IS and WITH ALL FAULTS.

# Set-WmiNamespaceSecurity.ps1
# Example: Set-WmiNamespaceSecurity root/cimv2 add steve Enable,RemoteAccess

Param ( [parameter(Mandatory=$true,Position=0)][string] $namespace,
    [parameter(Mandatory=$true,Position=1)][string] $operation,
    [parameter(Mandatory=$true,Position=2)][string] $account,
    [parameter(Position=3)][string[]] $permissions = $null,
    [bool] $allowInherit = $false,
    [bool] $deny = $false,
    [string] $computerName = ".",
    [System.Management.Automation.PSCredential] $credential = $null)

Process {
    $ErrorActionPreference = "Stop"

    Function Get-AccessMaskFromPermission($permissions) {
        $WBEM_ENABLE = 1
                $WBEM_METHOD_EXECUTE = 2
                $WBEM_FULL_WRITE_REP = 4
                $WBEM_PARTIAL_WRITE_REP = 8
                $WBEM_WRITE_PROVIDER = 0x10
                $WBEM_REMOTE_ACCESS = 0x20
                $WBEM_RIGHT_SUBSCRIBE = 0x40
                $WBEM_RIGHT_PUBLISH = 0x80
        $READ_CONTROL = 0x20000
        $WRITE_DAC = 0x40000

        $WBEM_RIGHTS_FLAGS = $WBEM_ENABLE,$WBEM_METHOD_EXECUTE,$WBEM_FULL_WRITE_REP,`
            $WBEM_PARTIAL_WRITE_REP,$WBEM_WRITE_PROVIDER,$WBEM_REMOTE_ACCESS,`
            $READ_CONTROL,$WRITE_DAC
        $WBEM_RIGHTS_STRINGS = "Enable","MethodExecute","FullWrite","PartialWrite",`
            "ProviderWrite","RemoteAccess","ReadSecurity","WriteSecurity"

        $permissionTable = @{}

        for ($i = 0; $i -lt $WBEM_RIGHTS_FLAGS.Length; $i++) {
            $permissionTable.Add($WBEM_RIGHTS_STRINGS[$i].ToLower(), $WBEM_RIGHTS_FLAGS[$i])
        }

        $accessMask = 0

        foreach ($permission in $permissions) {
            if (-not $permissionTable.ContainsKey($permission.ToLower())) {
                throw "Unknown permission: $permission`nValid permissions: $($permissionTable.Keys)"
            }
            $accessMask += $permissionTable[$permission.ToLower()]
        }

        $accessMask
    }

    if ($PSBoundParameters.ContainsKey("Credential")) {
        $remoteparams = @{ComputerName=$computer;Credential=$credential}
    } else {
        $remoteparams = @{ComputerName=$computerName}
    }

    $invokeparams = @{Namespace=$namespace;Path="__systemsecurity=@"} + $remoteParams

    $output = Invoke-WmiMethod @invokeparams -Name GetSecurityDescriptor
    if ($output.ReturnValue -ne 0) {
        throw "GetSecurityDescriptor failed: $($output.ReturnValue)"
    }

    $acl = $output.Descriptor
    $OBJECT_INHERIT_ACE_FLAG = 0x1
    $CONTAINER_INHERIT_ACE_FLAG = 0x2

    $computerName = (Get-WmiObject @remoteparams Win32_ComputerSystem).Name

    if ($account.Contains('\')) {
        $domainaccount = $account.Split('\')
        $domain = $domainaccount[0]
        if (($domain -eq ".") -or ($domain -eq "BUILTIN")) {
            $domain = $computerName
        }
        $accountname = $domainaccount[1]
    } elseif ($account.Contains('@')) {
        $domainaccount = $account.Split('@')
        $domain = $domainaccount[1].Split('.')[0]
        $accountname = $domainaccount[0]
    } else {
        $domain = $computerName
        $accountname = $account
    }

    $getparams = @{Class="Win32_Account";Filter="Domain='$domain' and Name='$accountname'"}

    $win32account = Get-WmiObject @getparams

    if ($win32account -eq $null) {
        throw "Account was not found: $account"
    }

    switch ($operation) {
        "add" {
            if ($permissions -eq $null) {
                throw "-Permissions must be specified for an add operation"
            }
            $accessMask = Get-AccessMaskFromPermission($permissions)

            $ace = (New-Object System.Management.ManagementClass("win32_Ace")).CreateInstance()
            $ace.AccessMask = $accessMask
            if ($allowInherit) {
                $ace.AceFlags = $OBJECT_INHERIT_ACE_FLAG + $CONTAINER_INHERIT_ACE_FLAG
            } else {
                $ace.AceFlags = 0
            }

            $trustee = (New-Object System.Management.ManagementClass("win32_Trustee")).CreateInstance()
            $trustee.SidString = $win32account.Sid
            $ace.Trustee = $trustee

            $ACCESS_ALLOWED_ACE_TYPE = 0x0
            $ACCESS_DENIED_ACE_TYPE = 0x1

            if ($deny) {
                $ace.AceType = $ACCESS_DENIED_ACE_TYPE
            } else {
                $ace.AceType = $ACCESS_ALLOWED_ACE_TYPE
            }

            $acl.DACL += $ace.psobject.immediateBaseObject
        }

        "delete" {
            if ($permissions -ne $null) {
                throw "Permissions cannot be specified for a delete operation"
            }

            [System.Management.ManagementBaseObject[]]$newDACL = @()
            foreach ($ace in $acl.DACL) {
                if ($ace.Trustee.SidString -ne $win32account.Sid) {
                    $newDACL += $ace.psobject.immediateBaseObject
                }
            }

            $acl.DACL = $newDACL.psobject.immediateBaseObject
        }

        default {
            throw "Unknown operation: $operation`nAllowed operations: add delete"
        }
    }

    $setparams = @{Name="SetSecurityDescriptor";ArgumentList=$acl.psobject.immediateBaseObject} + $invokeParams

    $output = Invoke-WmiMethod @setparams
    if ($output.ReturnValue -ne 0) {
        throw "SetSecurityDescriptor failed: $($output.ReturnValue)"
    }
}

```

If it still not working you can execute the faulty query to troubleshoot it with :

```auto
<font size="3"><font color="#0000ff">Get-WmiObject</font> <font color="#000080">-Query</font> <font color="#8b0000">"SELECT * from Win32_Process" ##Local##
<font color="#0000ff">Get-WmiObject</font> <font color="#000080">-Query</font> "SELECT * from Win32_Process" <strong>-ComputerName PC1 </strong>##Remote##
</font></font>

```

I hope this helps you.

---

<div class="post-metadata">

**Author:** ![Mike\_L](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/mike_l/32/11717_2.png) [@Mike\_L](https://community.dynatrace.com/u/Mike_L)\
**Post date:** [August 2, 2023, 1:36pm UTC](https://community.dynatrace.com/t/extension-v2-status-code-errors/40946/3 "2023-08-02T13:36:51Z")

</div>

I had a look through the source code as I don’t think it’s documented anywhere. This is the current definition of the error codes, including error 38:

OK StatusCodeType = 0  
GENERIC\_ERROR StatusCodeType = 27  
INVALID\_ARGS\_ERROR StatusCodeType = 28  
EEC\_CONNECTION\_ERROR StatusCodeType = 30  
INVALID\_CONFIG\_ERROR StatusCodeType = 32  
AUTHENTICATION\_ERROR StatusCodeType = 34  
DEVICE\_CONNECTION\_ERROR StatusCodeType = 38
