Module: Windows::Group

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/windows/group.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#group_absent(name, &block) ⇒ Object



48
49
50
# File 'lib/beaker/host/windows/group.rb', line 48

def group_absent(name, &block)
  execute("net localgroup /delete \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
end

#group_get(name) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/beaker/host/windows/group.rb', line 31

def group_get(name)
  execute("net localgroup \"#{name}\"") do |result|
    fail_test "failed to get group #{name}" if result.exit_code != 0

    yield result if block_given?
    result
  end
end

#group_gid(_name) ⇒ Object

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/beaker/host/windows/group.rb', line 40

def group_gid(_name)
  raise NotImplementedError, "Can't retrieve group gid on a Windows host"
end

#group_listObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/beaker/host/windows/group.rb', line 4

def group_list
  execute('cmd /c echo "" | wmic group where localaccount="true" get name /format:value') do |result|
    groups = []
    result.stdout.each_line do |line|
      groups << (line.match(/^Name=(.+)$/) or next)[1]
    end

    yield result if block_given?

    groups
  end
end

#group_list_using_powershellObject

using powershell commands as wmic is deprecated in windows 2025



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/beaker/host/windows/group.rb', line 18

def group_list_using_powershell
  execute('cmd /c echo "" | powershell.exe "Get-LocalGroup | Select-Object -ExpandProperty Name"') do |result|
    groups = []
    result.stdout.each_line do |line|
      groups << line.strip or next
    end

    yield result if block_given?

    groups
  end
end

#group_present(name, &block) ⇒ Object



44
45
46
# File 'lib/beaker/host/windows/group.rb', line 44

def group_present(name, &block)
  execute("net localgroup /add \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
end