Closed ili101 closed 6 years ago
This was reported as #1041 before; was closed as an issue with the module. What version of PowerCLI are you running?
VMware.PowerCLI Version : 10.1.1.8827524 I can't replicate the problem mentioned in #1041 so I don't think its identical
@ili101 Would you be able to try running it in the ISE, Visual Studio or another PowerShell IDE and report back? We just need to know if VSCode/the extension is causing this, or if this is a behaviour caused by the module itself.
Tested it in ISE, VSCode without Powershell extension and PowerShell Studio 2018 diden't get the error.
Thanks for that! I suspect it might be PSScriptAnalyzer thing, possibly importing the module in the background and creating the provider. I'll take a look, but given the specificity of the issue, it might require a community member with more familiarity with the VMWare.PowerCLI module (hence "Up-for-Grabs").
Yeah, do you get that same error if you import the same module twice in a regular PowerShell window?
PS > Import-Module VMware.PowerCLI
PS > Import-Module VMware.PowerCLI
I don't get the error importing it twice in regular PowerShell or in vscode-powershell
Can you try one more thing for me?
Open two PowerShell windows... run this in each while both open.
PS > Import-Module VMware.PowerCLI
Do you get the error?
I just want to find some repo outside of VSCode if possible.
Also if you don't mind try this as well
Import-Module VMware.PowerCLI
$ps = [powershell]::Create('NewRunspace').AddScript('Import-Module VMware.PowerCLI')
$ps.Invoke()
$ps.Streams.Error
$ps.InvocationStateInfo.Reason
@SeeminglyScience Nice catch! PowerCLI do not support multiple runspace https://communities.vmware.com/thread/513253 But I still don't understand way writing "Get-VM" in the editor triggers this bug? Do vscode-powershell spins a new runspace and load the module in it?
That was @rjmholt's catch :)
PSScriptAnalyzer (what creates syntax markers) runs in a separate runspace, and some rules cause modules to import. As a workaround you could disable script analysis by adding this to your workspace settings.
"powershell.scriptAnalysis.enable": false,
Ultimately the fix should come from VMWare, it seems like it's just an oversight. I'm not sure there is anything that can be done about it from this extension unfortunately.
Very theoretically it might be possible to make analysis happen in the same runspace? But there would be plenty of problems with that, and non-trivial work. I feel like for a workaround to an issue in a particular module, that's too high a price.
I tried looking through VMWare's scripts, but I'm guessing this part is done in C# -- it should be as simple as just checking if the drive already exists.
I tried looking through VMWare's scripts, but I'm guessing this part is done in C# -- it should be as simple as just checking if the drive already exists.
If by drive you mean PSDrive then it won't exist as they are specific to the ExecutionContext
. From the error message I'm guessing it's not really related to PSDrives but instead VMWare mounting to an ESX host/VCenter/etc. They probably need to store whatever handle they have for the mount statically so it can be pulled from another thread. If that's what you meant then ignore me 😉
Ah I didn't know any of that! Ok, that makes lots of sense. Thanks!
Closing this as a bug in the VMWare extension.
Issue Description
If you have the command "Get-VM" in your editor and you run "Import-Module VMware.PowerCLI" you get the error "Import-Module : The specified mount name 'vis' is already in use."
What is the Powershell extension doing when "Get-VM" is in the editor that brake the module import? is it partially loading something?
Steps to Reproduce
Environment Information
Visual Studio Code
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
|Extension|Author|Version| |---|---|---| |Bookmarks|alefragnani|0.19.1| |bracket-pair-colorizer|CoenraadS|1.0.58| |code-settings-sync|Shan|2.9.2| |githistory|donjayamanne|0.4.1| |gitlens|eamodio|8.4.1| |PowerShell|ms-vscode|1.7.0| |rest-client|humao|0.18.4| |snippet-creator|nikitaKunevich|0.0.4| |vscode-auto-scroll|pejmannikram|1.0.2| |vscode-icons|robertohuertasm|7.24.0| |vscode-postgres|ckolkman|1.0.9|;