Hi friends,
I'm using .Net System.Management.Automation.PowerShell object to invoke:
New-Item -Path "vmstore:\Test-DC\ESX_Log\ESX10.161.47.228" -ItemType Directory -Force
The returned error is:
The specified path does not refer to a drive created by this provider.
However, from PowerShell console the same command it works fine as shown below.
New-Item -Path "vmstore:\SiltecRX2-DC\ESX_Log\ESX10.161.47.229" -ItemType Directory -Force
Name Type Id
---- ---- --
ESX10.161.47.229 DatastoreFolder
Any help will be appreciated!
The following workaround worked for me:
1. Create a PSDrive with VimDatastore as the PS Provider.
2. create the directory using New-Item cmdlet with the created PSDrive as the drive letter.
3. Remove the PSDrive.
Here is the C# code I use:
PowerShell _powerShell;
_powerShell = PowerShell.Create();
_powerShell.AddScript($"Get-Datastore {datastoreName} | New-PSDrive -Name {PSDriveName} -PSProvider VimDatastore -Root \"\\\\\"");
_powerShell.AddScript($"New-Item -Path {PSDriveName}:\\{folderName} -ItemType Directory -Force");
_powerShell.AddScript($"Remove-PSDrive -Name {PSDriveName}");
Looks like you don't have the VimDatastore provider in that environment.
Did you check with Get-PSProvider?
That provider should normally be created when you run the Connect-VIServer
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, I will check.
It seems I have VimDatastore as one of the providers:
VMware.VimAutomation.Core\VimDatastore
Can you try if some basic functionality with the VimDatastore provider works?
Like
Get-Item -Path vmstore:
Get-childItem -Path vmstore:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried it and here are the results:
Get-Item -Path "vmstore:"
Cannot find path 'vmstore:\' because it does not exist
Get-childItem -Path "vmstore:"
Cannot find path '\LastConnectedVCenterServer\' because it does not exist.
That again seems to show that the provider is not set up correctly in that environment.
Sorry but I have no further experience with calling PS from a .Net environment.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for trying man:-)
It seems like I have some environment issue.
I will try to reinstall PowerCLI on my machine and update.
The following workaround worked for me:
1. Create a PSDrive with VimDatastore as the PS Provider.
2. create the directory using New-Item cmdlet with the created PSDrive as the drive letter.
3. Remove the PSDrive.
Here is the C# code I use:
PowerShell _powerShell;
_powerShell = PowerShell.Create();
_powerShell.AddScript($"Get-Datastore {datastoreName} | New-PSDrive -Name {PSDriveName} -PSProvider VimDatastore -Root \"\\\\\"");
_powerShell.AddScript($"New-Item -Path {PSDriveName}:\\{folderName} -ItemType Directory -Force");
_powerShell.AddScript($"Remove-PSDrive -Name {PSDriveName}");