puppetlabs/puppet · error · Puppet::Util::Windows::Error

Failed to get computer name

Error message

Failed to get computer name

What it means

Raised on Windows when the Win32 GetComputerNameW call fails while Puppet::Util::Windows::ADSI.computer_name caches the NetBIOS machine name used to build WinNT:// ADsPaths for user and group management. It raises Puppet::Util::Windows::Error, so the message is suffixed with the GetLastError details.

Source

Thrown at lib/puppet/util/windows/adsi.rb:57

      Puppet::Util::Windows::ADSI.connect(computer_uri).Create(resource_type, name)
    end

    def delete(name, resource_type)
      Puppet::Util::Windows::ADSI.connect(computer_uri).Delete(resource_type, name)
    end

    # taken from winbase.h
    MAX_COMPUTERNAME_LENGTH = 31

    def computer_name
      unless @computer_name
        max_length = MAX_COMPUTERNAME_LENGTH + 1 # NULL terminated
        FFI::MemoryPointer.new(max_length * 2) do |buffer| # wide string
          FFI::MemoryPointer.new(:dword, 1) do |buffer_size|
            buffer_size.write_dword(max_length) # length in TCHARs

            if GetComputerNameW(buffer, buffer_size) == FFI::WIN32_FALSE
              raise Puppet::Util::Windows::Error, _("Failed to get computer name")
            end

            @computer_name = buffer.read_wide_string(buffer_size.read_dword)
          end
        end
      end
      @computer_name
    end

    def computer_uri(host = '.')
      "WinNT://#{host}"
    end

    def wmi_resource_uri(host = '.')
      "winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2"
    end

    # This method should *only* be used to generate WinNT://<SID> style monikers

View on GitHub (pinned to e227c27540)

Solutions

  1. Retry once the machine is fully booted; sanity-check with `hostname` in cmd.
  2. Check the System event log for RPC or Workstation-service failures around the time of the error.
  3. If reproducible on a healthy machine, report to Puppet with the win32 error code included in the exception message.
Defensive patterns

Strategy: fallback

Try / catch

begin
  name = Puppet::Util::Windows::ADSI.computer_name
rescue Puppet::Util::Windows::Error
  name = Socket.gethostname # best-effort fallback
end

Prevention

When it happens

Trigger: Any Windows code path touching ADSI (user/group resources, principal resolution) when GetComputerNameW returns FALSE — for example the RPC/workstation subsystem not being ready during very early boot or service startup, or the buffer/length contract failing.

Common situations: Rare in practice; seen on unhealthy or freshly-booting machines, or second-hand inside stack traces from ADSI operations.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/2c28802f14772c4f. Report an issue: GitHub.