The auto-loading of the modules is probably not working when using PS from C#.
A solution could be to import the required modules in the code, before calling a cmdlet.
Note that you will have to provide the full path to the module, see for example https://stackoverflow.com/questions/17070747/importing-powershell-module-in-c-sharp
It is not the same case.
First, my script code exactly load needed module- code is
Import-Module VMware.VimAutomation.Vds -ErrorAction Stop
Second- i try to run script throw command- line and not throw PS object . Simply create process by calling cmd.exe ( invisible stte) and command-line "Powershell -file "path-to-file" parameters= "all other paramenets".
Powershell starts executions- but stops on line i wrote
Did you check in your script if the modules are effectively loaded after the Import-Module?
Did you check if the $env:PSModulePath variable is set correctly to include the location of the PowerCLI modules?
This is the question.
Module NOT effectively imported if I try to run script from service ( C# code) and loaded ( and script make its work)it I run it from console.
May be problem really that in this computer $env:PSModuleP differ if i run it from different processes?
Or- can it occur because code is 32bit?
It is one specific computer- in other clients ( and in my development computer -windows 7) system works. And we can not fix the problem
Did you check in your script what the content of the $env:PSModulePath variable is?
One way of doing that would be to use the Start-Transcript cmdlet and then just display the content of the variable.
That way you can find back in the transcript log what it shows.
32- or 64-bit normally shouldn't make a difference.
That is the question.
I added logging of $env:PSModulePass in beginning of script.
When i run script directly from command line, path to VMVare installation included in directories listed in path
When I run command- line from C# code- this directory NOT included in path.
What it can be and what can I do with this?
I understand the problem.
Loggingof system variables ( PSModulesPath and username) helps me.
My program run as system service, as appropriate username. And VMware extension was installed for specific user and not for all users- as result VMVare modules path was invisible for service- and visible for command-line running
Thank you. Problem looks fixed