PowershellDirect on Windows Server 2016: Invoke-Command -VMName 'blah' fails with Unable to cast object of type 'System.String' to type 'VMState'.
See original GitHub issueSteps to reproduce
$vmUserPassword = 'password'; #reproes even without correct password
$vmUser = '.\Administrator';
$vmMachineName = 'MyLocalVMName'; #this VM needs to exist
$password = ConvertTo-SecureString $vmUserPassword -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($vmUser, $password);
Invoke-Command -VMName $vmMachineName -Credential $cred { Write-Output ('Connection'+'Succeeded') }
Expected behavior
ConnectionSucceeded
Actual behavior
Invoke-Command: Unable to cast object of type 'System.String' to type 'VMState'.
Environment data
Name Value
---- -----
PSVersion 7.1.1
PSEdition Core
GitCommitId 7.1.1
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Notes:
- this is about the host, rather than guest guest:
- Win10 or Windows Server 2019 host + Windows Server 2019 guest => works
- Windows Server 2016 host + Windows Server 2019 guest => breaks
- this is specific to powershell core
- the same command works from Powershell ISE 5.1.14393.3866 from either host
- In my actual environment I use powershell SDK from c# app, but thankfully it reproes from regular powershell
- Similar unanswered question on stackoverflow .
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (1 by maintainers)
Top Results From Across the Web
Manage Windows Virtual Machines with PowerShell Direct
Problem : Enter-PSSession , Invoke-Command , or New-PSSession do not have a -VMName or -VMId parameter. Potential causes: The most likely issue ......
Read more >PowerShell issue: Invoke method "Cannot cast object of ...
Once running the code, an error occurs in the function Invoke, it is saying that "it cannot cast System.String to the type System.String[]"....
Read more >Manage Windows virtual machines with PowerShell Direct
In this article. Create and exit a PowerShell Direct session using PSSession cmdlets; Run script or command with Invoke-Command cmdlet; What's ...
Read more >Invoke Power Shell: Unable to cast object of type 'System. ...
I am facing this issue ->Invoke Power Shell: Unable to cast object of type 'System.String' to type 'System.Management.Automation.PSModuleInfo.
Read more >PowerShell Direct Deep Dive HyperV #WS2016 ...
Hello folks,. Microsoft introduced a new feature in Windows Server 2016 called PowerShell Direct. What is PowerShell Direct?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m guessing the 2016 version is using implicit remoting (or w/e the automatic wincompat layer is called, I forget) due to the HyperV module not getting the
Core
tag via Windows Updates. As a workaround tryImport-Module HyperV -SkipEditionCheck
before running the command.Ack. We’re ok with workaround, and will probably speed up deprecation of Server 2016 as a supported host. Not sure what is the protocol for closing the bugs, but I’m Ok with closing