Sha256: da4950aab1440efe68c63012a8a7c905798e77f300b3c1de3f4ea42d1f99ff0f

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 KB

Contents

require_relative "subprocess"
require_relative "which"

module Vagrant
  module Util
    # Executes PowerShell scripts.
    #
    # This is primarily a convenience wrapper around Subprocess that
    # properly sets powershell flags for you.
    class PowerShell
      def self.available?
        !!Which.which("powershell")
      end

      # Execute a powershell script.
      #
      # @param [String] path Path to the PowerShell script to execute.
      # @return [Subprocess::Result]
      def self.execute(path, *args, **opts, &block)
        command = [
          "powershell",
          "-NoProfile",
          "-ExecutionPolicy", "Bypass",
          "&('#{path}')",
          args
        ].flatten

        # Append on the options hash since Subprocess doesn't use
        # Ruby 2.0 style options yet.
        command << opts

        Subprocess.execute(*command, &block)
      end

      # Returns the version of PowerShell that is installed.
      #
      # @return [String]
      def self.version
        command = [
          "powershell",
          "-NoProfile",
          "-ExecutionPolicy", "Bypass",
          "$PSVersionTable.PSVersion.Major"
        ].flatten

        r = Subprocess.execute(*command)
        return nil if r.exit_code != 0
        return r.stdout.chomp
      end
    end
  end
end

Version data entries

16 entries across 13 versions & 4 rubygems

Version Path
vagrant-unbundled-1.9.1.1 lib/vagrant/util/powershell.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/powershell.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/powershell.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/powershell.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/powershell.rb
vagrant-unbundled-1.8.5.2 lib/vagrant/util/powershell.rb
vagrant-unbundled-1.8.5.1 lib/vagrant/util/powershell.rb
vagrant-unbundled-1.8.4.2 lib/vagrant/util/powershell.rb
vagrant-unbundled-1.8.4.1 lib/vagrant/util/powershell.rb
vagrant-unbundled-1.8.1.2 lib/vagrant/util/powershell.rb
vagrant-unbundled-1.8.1.1 lib/vagrant/util/powershell.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-272fb27e0536/lib/vagrant/util/powershell.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/lib/vagrant/util/powershell.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/lib/vagrant/util/powershell.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/lib/vagrant/util/powershell.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/lib/vagrant/util/powershell.rb