Sha256: ef4756fc0ff0dd5b85d7401904d02168cd8c4e7d1226a54e19193df2d3058428

Contents?: true

Size: 828 Bytes

Versions: 33

Compression:

Stored size: 828 Bytes

Contents

module PSWindows::User
  include Beaker::CommandFactory

  def user_list(&block)
    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, &block)
    execute("net user \"#{name}\"") do |result|
      fail_test "failed to get user #{name}" if result.exit_code != 0

      yield result if block_given?
    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

33 entries across 33 versions & 1 rubygems

Version Path
beaker-3.37.0 lib/beaker/host/pswindows/user.rb
beaker-3.36.0 lib/beaker/host/pswindows/user.rb
beaker-3.35.0 lib/beaker/host/pswindows/user.rb
beaker-3.34.0 lib/beaker/host/pswindows/user.rb
beaker-3.33.0 lib/beaker/host/pswindows/user.rb
beaker-3.32.0 lib/beaker/host/pswindows/user.rb
beaker-3.31.0 lib/beaker/host/pswindows/user.rb
beaker-3.30.0 lib/beaker/host/pswindows/user.rb
beaker-3.29.0 lib/beaker/host/pswindows/user.rb
beaker-3.28.0 lib/beaker/host/pswindows/user.rb
beaker-3.27.0 lib/beaker/host/pswindows/user.rb
beaker-3.26.0 lib/beaker/host/pswindows/user.rb
beaker-3.25.0 lib/beaker/host/pswindows/user.rb
beaker-3.24.0 lib/beaker/host/pswindows/user.rb
beaker-3.23.0 lib/beaker/host/pswindows/user.rb
beaker-3.22.0 lib/beaker/host/pswindows/user.rb
beaker-3.21.1 lib/beaker/host/pswindows/user.rb
beaker-3.21.0 lib/beaker/host/pswindows/user.rb
beaker-3.20.0 lib/beaker/host/pswindows/user.rb
beaker-3.19.0 lib/beaker/host/pswindows/user.rb