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-2.3.6.0 plugins/hosts/windows/cap/ps.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.3.3.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.3.2.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.19.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.18.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.16.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.14.0 plugins/hosts/windows/cap/ps.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.10.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.9.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.8.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.7.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.6.2 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.6.1 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.6.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.5.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.4.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.3.0 plugins/hosts/windows/cap/ps.rb
vagrant-unbundled-2.2.2.0 plugins/hosts/windows/cap/ps.rb