Sha256: 5371524d9b936e73b421d62990ec8e852b3e7caaebe12aaa4be3abaf326b3a12

Contents?: true

Size: 1.41 KB

Versions: 47

Compression:

Stored size: 1.41 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 << encoded(command)
          if ps_info[:extra_args]
            args << ps_info[:extra_args]
          end

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

        def self.encoded(script)
          encoded_script = script.encode('UTF-16LE', 'UTF-8')
          Base64.strict_encode64(encoded_script)
        end
      end
    end
  end
end

Version data entries

47 entries across 43 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.8.1 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-1.9.7.1 plugins/hosts/windows/cap/ps.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/hosts/windows/cap/ps.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/hosts/windows/cap/ps.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/hosts/windows/cap/ps.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-1.9.5.1 plugins/hosts/windows/cap/ps.rb