Sha256: 4d8c905b4d71ce0c18fd700df451cc9dc2bec964bf881cd34f9f12979e4c30c3

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

require "pathname"
require "tmpdir"

require "vagrant/util/safe_exec"

module VagrantPlugins
  module HostWindows
    module Cap
      class PS
        def self.ps_client(env, ps_info)
          logger = Log4r::Logger.new("vagrant::hosts::windows")

          command = <<-EOS
            $plain_password = "#{ps_info[:password]}"
            $username = "#{ps_info[:username]}"
            $port = "#{ps_info[:port]}"
            $hostname = "#{ps_info[:host]}"
            $password = ConvertTo-SecureString $plain_password -asplaintext -force
            $creds = New-Object System.Management.Automation.PSCredential ("$hostname\\$username", $password)
            function prompt { kill $PID }
            Enter-PSSession -ComputerName $hostname -Credential $creds -Port $port
          EOS

          logger.debug("Starting remote powershell with command:\n#{command}")

          args = ["-NoProfile"]
          args << "-ExecutionPolicy"
          args << "Bypass"
          args << "-NoExit"
          args << "-EncodedCommand"
          args << ::WinRM::PowershellScript.new(command).encoded
          if ps_info[:extra_args]
            args << ps_info[:extra_args]
          end

          # Launch it
          Vagrant::Util::SafeExec.exec("powershell", *args)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
vagrant-unbundled-1.9.1.1 plugins/hosts/windows/cap/ps.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/hosts/windows/cap/ps.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/hosts/windows/cap/ps.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/hosts/windows/cap/ps.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-1.8.5.2 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-1.8.5.1 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-1.8.4.2 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-1.8.4.1 plugins/hosts/windows/cap/ps.rb