diff --git a/CHANGELOG.md b/CHANGELOG.md index 11d732745..32a0693e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ IMPROVEMENTS: to convey actual meaning. - commands/plugin: Listing plugins now has machine-readable output. [GH-3293] - guests/omnios: Mount NFS capability [GH-3282] + - synced\_folders/smb: Verify PowerShell v3 or later is running. [GH-3257] BUG FIXES: diff --git a/lib/vagrant/util/powershell.rb b/lib/vagrant/util/powershell.rb index 7baba26ce..7357d829d 100644 --- a/lib/vagrant/util/powershell.rb +++ b/lib/vagrant/util/powershell.rb @@ -31,6 +31,22 @@ module Vagrant 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 diff --git a/plugins/synced_folders/smb/errors.rb b/plugins/synced_folders/smb/errors.rb index 697829833..f73d04bfa 100644 --- a/plugins/synced_folders/smb/errors.rb +++ b/plugins/synced_folders/smb/errors.rb @@ -18,6 +18,10 @@ module VagrantPlugins error_key(:powershell_error) end + class PowershellVersion < SMBError + error_Key(:powershell_version) + end + class WindowsHostRequired < SMBError error_key(:windows_host_required) end diff --git a/plugins/synced_folders/smb/scripts/ps_version.ps1 b/plugins/synced_folders/smb/scripts/ps_version.ps1 new file mode 100644 index 000000000..89fbab28e --- /dev/null +++ b/plugins/synced_folders/smb/scripts/ps_version.ps1 @@ -0,0 +1 @@ +Write-Output $PSVersionTable.PSVersion.Major diff --git a/plugins/synced_folders/smb/synced_folder.rb b/plugins/synced_folders/smb/synced_folder.rb index d3f1f8963..6cc177bbd 100644 --- a/plugins/synced_folders/smb/synced_folder.rb +++ b/plugins/synced_folders/smb/synced_folder.rb @@ -27,6 +27,15 @@ module VagrantPlugins return false end + psv = Vagrant::Util::PowerShell.version.to_i + if psv < 3 + if raise_error + raise Errors::PowershellVersion, + version: psv.to_s + end + return false + end + true end diff --git a/templates/locales/synced_folder_smb.yml b/templates/locales/synced_folder_smb.yml index 140bd0244..442c99405 100644 --- a/templates/locales/synced_folder_smb.yml +++ b/templates/locales/synced_folder_smb.yml @@ -39,6 +39,10 @@ en: Error: %{stderr} + powershell_version: |- + PowerShell version 3 or later is required for SMB synced folders + to work on Windows. You have version: '%{version}'. Please update + your PowerShell installation. windows_admin_required: |- SMB shared folders require running Vagrant with administrative privileges. This is a limitation of Windows, since creating new