Sha256: 804a4584cad35e2ecf194422743539b5676f3e167d735c5da6ec4df7c10c6125

Contents?: true

Size: 827 Bytes

Versions: 8

Compression:

Stored size: 827 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

8 entries across 8 versions & 1 rubygems

Version Path
beaker-4.42.0 lib/beaker/host/pswindows/user.rb
beaker-4.41.2 lib/beaker/host/pswindows/user.rb
beaker-4.41.1 lib/beaker/host/pswindows/user.rb
beaker-4.41.0 lib/beaker/host/pswindows/user.rb
beaker-4.40.2 lib/beaker/host/pswindows/user.rb
beaker-4.40.1 lib/beaker/host/pswindows/user.rb
beaker-4.40.0 lib/beaker/host/pswindows/user.rb
beaker-4.39.0 lib/beaker/host/pswindows/user.rb