Sha256: 5ccebbbc4f9d5c837f417ebec2a99401bc9938658cd698bcb04593c488a4fc41

Contents?: true

Size: 968 Bytes

Versions: 52

Compression:

Stored size: 968 Bytes

Contents

module PSWindows::Group
  include Beaker::CommandFactory

  def group_list(&block)
    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

  def group_get(name, &block)
    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

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

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

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

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
beaker-4.25.0 lib/beaker/host/pswindows/group.rb
beaker-4.24.0 lib/beaker/host/pswindows/group.rb
beaker-4.23.2 lib/beaker/host/pswindows/group.rb
beaker-4.23.1 lib/beaker/host/pswindows/group.rb
beaker-4.23.0 lib/beaker/host/pswindows/group.rb
beaker-4.22.1 lib/beaker/host/pswindows/group.rb
beaker-4.22.0 lib/beaker/host/pswindows/group.rb
beaker-4.21.0 lib/beaker/host/pswindows/group.rb
beaker-4.20.0 lib/beaker/host/pswindows/group.rb
beaker-4.19.0 lib/beaker/host/pswindows/group.rb
beaker-4.18.0 lib/beaker/host/pswindows/group.rb
beaker-4.17.0 lib/beaker/host/pswindows/group.rb
beaker-4.16.0 lib/beaker/host/pswindows/group.rb
beaker-4.15.0 lib/beaker/host/pswindows/group.rb
beaker-4.14.1 lib/beaker/host/pswindows/group.rb
beaker-4.14.0 lib/beaker/host/pswindows/group.rb
beaker-4.13.1 lib/beaker/host/pswindows/group.rb
beaker-4.13.0 lib/beaker/host/pswindows/group.rb
beaker-4.12.0 lib/beaker/host/pswindows/group.rb
beaker-4.11.1 lib/beaker/host/pswindows/group.rb