Sha256: b5f6414236ad3d03a0c2f42352faab4beabdf07e52bc0c13bd2cf2a6c82129f4

Contents?: true

Size: 854 Bytes

Versions: 41

Compression:

Stored size: 854 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=([\w ]+)/) 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}" unless result.stdout =~ /^User name\s+#{name}/

      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

41 entries across 41 versions & 1 rubygems

Version Path
beaker-2.33.0 lib/beaker/host/pswindows/user.rb
beaker-2.32.1 lib/beaker/host/pswindows/user.rb
beaker-2.32.0 lib/beaker/host/pswindows/user.rb
beaker-2.31.0 lib/beaker/host/pswindows/user.rb
beaker-2.30.1 lib/beaker/host/pswindows/user.rb
beaker-2.30.0 lib/beaker/host/pswindows/user.rb
beaker-2.29.1 lib/beaker/host/pswindows/user.rb
beaker-2.29.0 lib/beaker/host/pswindows/user.rb
beaker-2.28.0 lib/beaker/host/pswindows/user.rb
beaker-2.27.0 lib/beaker/host/pswindows/user.rb
beaker-2.26.0 lib/beaker/host/pswindows/user.rb
beaker-2.25.0 lib/beaker/host/pswindows/user.rb
beaker-2.24.0 lib/beaker/host/pswindows/user.rb
beaker-2.23.0 lib/beaker/host/pswindows/user.rb
beaker-2.22.0 lib/beaker/host/pswindows/user.rb
beaker-2.21.0 lib/beaker/host/pswindows/user.rb
beaker-2.20.0 lib/beaker/host/pswindows/user.rb
beaker-2.19.0 lib/beaker/host/pswindows/user.rb
beaker-2.18.3 lib/beaker/host/pswindows/user.rb
beaker-2.18.2 lib/beaker/host/pswindows/user.rb