Sha256: 838f7460df6033cbfd01092a823084faff8ceab0cc81293fae24626d0e39d60d

Contents?: true

Size: 831 Bytes

Versions: 16

Compression:

Stored size: 831 Bytes

Contents

module PSWindows::User
  include Beaker::CommandFactory

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

      yield result if block_given?

      users
    end
  end

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

      yield result if block_given?
      result
    end
  end

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

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
beaker-6.4.1 lib/beaker/host/pswindows/user.rb
beaker-6.4.0 lib/beaker/host/pswindows/user.rb
beaker-6.3.0 lib/beaker/host/pswindows/user.rb
beaker-6.2.0 lib/beaker/host/pswindows/user.rb
beaker-6.1.0 lib/beaker/host/pswindows/user.rb
beaker-5.8.1 lib/beaker/host/pswindows/user.rb
beaker-5.8.0 lib/beaker/host/pswindows/user.rb
beaker-5.7.0 lib/beaker/host/pswindows/user.rb
beaker-5.6.0 lib/beaker/host/pswindows/user.rb
beaker-5.5.0 lib/beaker/host/pswindows/user.rb
beaker-5.4.0 lib/beaker/host/pswindows/user.rb
beaker-5.3.1 lib/beaker/host/pswindows/user.rb
beaker-5.3.0 lib/beaker/host/pswindows/user.rb
beaker-5.2.0 lib/beaker/host/pswindows/user.rb
beaker-5.1.0 lib/beaker/host/pswindows/user.rb
beaker-5.0.0 lib/beaker/host/pswindows/user.rb