Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Trouble with psdrive when the powershell script is run from c#.

$
0
0

Hi everyone,

I am trying to make a program in c# that manipulates the files in a datastore. When I run the script in powershell it works perfectly but when I use a c# pipeline, the vmware psdrives (vi, vis, vmstore, vmstores) are non-existent. I know that the snapin vmware.vimautomation.core is being added properly because it can execute connect-viserver and some other vmware commands. Any help with this problem will be much appreciated.

 

This is my powershell script:

 

Param (

[string]$server,

[string]$user,

[string]$pass,

 

 

[string]$vmName,

[string]$sourcePath,

[string]$dataStorename,

[string]$resourcePoolname

)

 

 

Add-PSSnapin VMware.VimAutomation.Vds

Add-PSSnapin VMware.VimAutomation.License

Add-PSSnapin vmware.vimautomation.core

Add-PSSnapin VMware.DeployAutomation

Add-PSSnapin VMware.ImageBuilder

Add-PSSnapin VMware.VimAutomation.Cloud

 

 

powershell.exe initialize-PowerCLIEnvironment.ps1

 

 

## Connect to the server ##

echo "Connecting to VIServer..."

Connect-VIServer -Server $server -user $user -password $pass

echo "Mounting the datastore..."

## End connect to server ##

 

 

$datastore = get-datastore $dataStorename

$resourcepool = $resourcePoolname

 

 

New-PSDrive -location $datastore -name ds -PSProvider VimDatastore -Root "\"

 

 

get-psdrive


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>