When using the vagrant powershell command from PowerShell 7.5.4 the session cannot be automatically created and a prompt for entering username/password is displayed.
The issue does not appear with the system PowerShell 5.1.26100.7462.
Debug output
Before running the vagrant powershell command I opened a new shell without loading the profile (pwsh.exe -NoProfile) and did the following:
vagrant init gusztavvargadr/windows-11-24h2-enterprise --box-version 2511.0.0
vagrant up
Output of vagrant powershell --debug:
DEBUG host: Searching for cap: ps_client
DEBUG host: Checking in: windows
DEBUG host: Found cap: ps_client in windows
INFO host: Execute capability: ps_client [#<Vagrant::Environment: C:/REDACTED>, {:host=>"127.0.0.1", :port=>55985, :username=>"vagrant", :password=>"vagrant", :extra_args=>nil}] (windows)
DEBUG windows: Starting remote powershell with command:
$plain_password = "vagrant"
$username = "vagrant"
$port = "55985"
$hostname = "127.0.0.1"
$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
DEBUG safe_exec: Converting command and arguments to common UTF-8 encoding for exec.
DEBUG safe_exec: Command: `"powershell"` Args: `["-NoProfile", "-ExecutionPolicy", "Bypass", "-NoExit", "-EncodedCommand", "IAAgACAAIAAgACAAIAAgACAAIAAgACAAJABwAGwAYQBpAG4AXwBwAGEAcwBzAHcAbwByAGQAIAA9ACAAIgB2AGEAZwByAGEAbgB0ACIACgAgACAAIAAgACAAIAAgACAAIAAgACAAIAAkAHUAcwBlAHIAbgBhAG0AZQAgAD0AIAAiAHYAYQBnAHIAYQBuAHQAIgAKACAAIAAgACAAIAAgACAAIAAgACAAIAAgACQAcABvAHIAdAAgAD0AIAAiADUANQA5ADgANQAiAAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJABoAG8AcwB0AG4AYQBtAGUAIAA9ACAAIgAxADIANwAuADAALgAwAC4AMQAiAAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJABwAGEAcwBzAHcAbwByAGQAIAA9ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBTAGUAYwB1AHIAZQBTAHQAcgBpAG4AZwAgACQAcABsAGEAaQBuAF8AcABhAHMAcwB3AG8AcgBkACAALQBhAHMAcABsAGEAaQBuAHQAZQB4AHQAIAAtAGYAbwByAGMAZQAKACAAIAAgACAAIAAgACAAIAAgACAAIAAgACQAYwByAGUAZABzACAAPQAgAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABTAHkAcwB0AGUAbQAuAE0AYQBuAGEAZwBlAG0AZQBuAHQALgBBAHUAdABvAG0AYQB0AGkAbwBuAC4AUABTAEMAcgBlAGQAZQBuAHQAaQBhAGwAIAAoACIAJABoAG8AcwB0AG4AYQBtAGUAXAAkAHUAcwBlAHIAbgBhAG0AZQAiACwAIAAkAHAAYQBzAHMAdwBvAHIAZAApAAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAAZgB1AG4AYwB0AGkAbwBuACAAcAByAG8AbQBwAHQAIAB7ACAAawBpAGwAbAAgACQAUABJAEQAIAB9AAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAARQBuAHQAZQByAC0AUABTAFMAZQBzAHMAaQBvAG4AIAAtAEMAbwBtAHAAdQB0AGUAcgBOAGEAbQBlACAAJABoAG8AcwB0AG4AYQBtAGUAIAAtAEMAcgBlAGQAZQBuAHQAaQBhAGwAIAAkAGMAcgBlAGQAcwAgAC0AUABvAHIAdAAgACQAcABvAHIAdAAKAA=="]`
DEBUG safe_exec: Converted - Command: `"powershell"` Args: `["-NoProfile", "-ExecutionPolicy", "Bypass", "-NoExit", "-EncodedCommand", "IAAgACAAIAAgACAAIAAgACAAIAAgACAAJABwAGwAYQBpAG4AXwBwAGEAcwBzAHcAbwByAGQAIAA9ACAAIgB2AGEAZwByAGEAbgB0ACIACgAgACAAIAAgACAAIAAgACAAIAAgACAAIAAkAHUAcwBlAHIAbgBhAG0AZQAgAD0AIAAiAHYAYQBnAHIAYQBuAHQAIgAKACAAIAAgACAAIAAgACAAIAAgACAAIAAgACQAcABvAHIAdAAgAD0AIAAiADUANQA5ADgANQAiAAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJABoAG8AcwB0AG4AYQBtAGUAIAA9ACAAIgAxADIANwAuADAALgAwAC4AMQAiAAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJABwAGEAcwBzAHcAbwByAGQAIAA9ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBTAGUAYwB1AHIAZQBTAHQAcgBpAG4AZwAgACQAcABsAGEAaQBuAF8AcABhAHMAcwB3AG8AcgBkACAALQBhAHMAcABsAGEAaQBuAHQAZQB4AHQAIAAtAGYAbwByAGMAZQAKACAAIAAgACAAIAAgACAAIAAgACAAIAAgACQAYwByAGUAZABzACAAPQAgAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABTAHkAcwB0AGUAbQAuAE0AYQBuAGEAZwBlAG0AZQBuAHQALgBBAHUAdABvAG0AYQB0AGkAbwBuAC4AUABTAEMAcgBlAGQAZQBuAHQAaQBhAGwAIAAoACIAJABoAG8AcwB0AG4AYQBtAGUAXAAkAHUAcwBlAHIAbgBhAG0AZQAiACwAIAAkAHAAYQBzAHMAdwBvAHIAZAApAAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAAZgB1AG4AYwB0AGkAbwBuACAAcAByAG8AbQBwAHQAIAB7ACAAawBpAGwAbAAgACQAUABJAEQAIAB9AAoAIAAgACAAIAAgACAAIAAgACAAIAAgACAARQBuAHQAZQByAC0AUABTAFMAZQBzAHMAaQBvAG4AIAAtAEMAbwBtAHAAdQB0AGUAcgBOAGEAbQBlACAAJABoAG8AcwB0AG4AYQBtAGUAIAAtAEMAcgBlAGQAZQBuAHQAaQBhAGwAIAAkAGMAcgBlAGQAcwAgAC0AUABvAHIAdAAgACQAcABvAHIAdAAKAA=="]`
ConvertTo-SecureString : The 'ConvertTo-SecureString' command was found in the module 'Microsoft.PowerShell.Security', but the
module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.
At line:5 char:25
+ $password = ConvertTo-SecureString $plain_password -aspla ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ConvertTo-SecureString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password"
is null. Change the value of argument "password" to a non-null value."
At line:6 char:22
+ ... $creds = New-Object System.Management.Automation.PSCredential ("$h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
The error comes from:
|
$password = ConvertTo-SecureString $plain_password -asplaintext -force |
Note that the error persists regardless of importing the module Microsoft.PowerShell.Security before running the command. The module can be otherwise imported in the shell and the ConvertTo-SecureString cmdlet can be ran.
Expected behavior
I expected the PowerShell session to be connected without being prompted for username and password.
Actual behavior
The command fails with an error informing that the Microsoft.PowerShell.Security module could not be loaded.
Reproduction information
Vagrant version
Host operating system
- Windows 11 Pro, 24H2, 26100.7462
Version of PowerShell 7.5.4, which does not work:
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Version of working system PowerShell:
Name Value
---- -----
PSVersion 5.1.26100.7462
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.7462
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Guest operating system
Windows 11 24H2 Enterprise from:
gusztavvargadr/windows-11-24h2-enterprise --box-version 2511.0.0
Steps to reproduce
- Start fresh PowerShell 7 shell with
pwsh.exe -NoProfile
- Pull and initialize the box mentioned above
- Run
vagrant powershell --debug
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "gusztavvargadr/windows-11-24h2-enterprise"
config.vm.box_version = "2511.0.0"
config.vm.synced_folder ".", "/vagrant", disabled: true
end
When using the
vagrant powershellcommand from PowerShell 7.5.4 the session cannot be automatically created and a prompt for entering username/password is displayed.The issue does not appear with the system PowerShell 5.1.26100.7462.
Debug output
Before running the
vagrant powershellcommand I opened a new shell without loading the profile (pwsh.exe -NoProfile) and did the following:Output of
vagrant powershell --debug:The error comes from:
vagrant/plugins/hosts/windows/cap/ps.rb
Line 21 in e15df81
Note that the error persists regardless of importing the module
Microsoft.PowerShell.Securitybefore running the command. The module can be otherwise imported in the shell and theConvertTo-SecureStringcmdlet can be ran.Expected behavior
I expected the PowerShell session to be connected without being prompted for username and password.
Actual behavior
The command fails with an error informing that the
Microsoft.PowerShell.Securitymodule could not be loaded.Reproduction information
Vagrant version
Host operating system
Version of PowerShell 7.5.4, which does not work:
Version of working system PowerShell:
Guest operating system
Windows 11 24H2 Enterprise from:
Steps to reproduce
pwsh.exe -NoProfilevagrant powershell --debugVagrantfile