VMware Cloud Community
arvindathere
Enthusiast
Enthusiast

New-PSDrive throwing exception A drive with the name 'vmstores' does not exist.

Hi @LucD ,

Am trying download vmx file from an application wrriten using C# and powershell.

When i call the below lines from powershell console it works.

$drive = New-PSDrive -Location $datastore -Name $mapName -PSProvider VimDatastore -Root "\" -Verbose -ErrorAction Stop

if ($drive -eq $null)
{
            Write-Log "Ps Drive map $mapName creation failed $($Error[0].Exception.Message)"
}

From C# it throws below exception.

Exception : Cannot find drive. A drive with the name 'vmstores' does not exist.

https://www.lucd.info/knowledge-base/vsc-and-powerclis-viminventory-and-vimdatastore-providers/

Referred your post above.

1) Printed $host and $host.Name 

$host value is System.Management.Automation.Internal.Host.InternalHost -

$host.Name is Default Host

2) Also tried to Import-Module -Name VMware.PowerCLI 6> $null within the powershell instance before opening runspace.

Facing same error.  Any way to successfuly run New-PSDrive command from C# application without above exception ?

Appreciate any help.

Regards,

Arvind

 

 

 

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Did you run a Get-PSProvider from your code?
Which providers are listed?
Any difference if you explicitly load the PowerCLI module as mentioned?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arvindathere
Enthusiast
Enthusiast

Hi @LucD 

Get-PSProvider results are below . VimDatastore Drives are empty in C# application

From powershell

PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-PSProvider

Name Capabilities Drives
---- ------------ ------
Registry ShouldProcess, Transactions {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {C, A, D}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}
VimInventory None {vis, vi}
VimDatastore Filter, ShouldProcess {vmstores, vmstore, ds, 1_rhel_7_3_arvind_recovery}
Certificate ShouldProcess {Cert}
WSMan Credentials {WSMan}

From C# application (after loading explicitly)


Name Capabilities Drives
---- ------------ ------
Registry ShouldProcess, Transactions {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {C, A, D}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}
Certificate ShouldProcess {Cert}
WSMan Credentials {WSMan}
VimInventory None {}
VimDatastore Filter, ShouldProcess {}

 

Reply
0 Kudos
LucD
Leadership
Leadership

I'm afraid I have no experience with C# and PowerCLI.
I would suggest opening an SR, but I suspect you will need a Developer Support contract for that.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arvindathere
Enthusiast
Enthusiast

Okay @LucD  . Thank you .. Will see if I can raise SR .

 

Reply
0 Kudos