VMWARE提供的SDK文档实在太难懂. 搞不懂为啥不直接给web service的引用文档. 对着提供的对象属性一边猜一边尝试, 进展颇微.
茶歇的时候翻了翻vmware提供的powershell toolkit, 感觉这个东西很有趣, 想了想部分功能用这东西做workaround不错, 以前也看过一些关于powershell的文档, 据说powershell里面到处都是对象, 用起来会比较顺手, 而且集成到.net程序里也方便, 但是一直对这东西是处于"知道"的阶段, 还从来没用过, 试试看吧, 事先想到了这样的缺点 -- 有可能性能上会产生瓶颈. 实际上优点也是显而易见的 -- 省掉了很多自己封装功能的工作量...
花了点小时间一边吃东西一边上网查解决办法, 把一个ugly的helloworld调通了, 记录几点过程中有用的tips, 都是网上找来的办法, 写下来再还给网络:
1. 先装powershell, 再装VMware提供的vSphere PowerCLI, 运行的时候会有这样的错误:
File C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-VIToolkitEnvironment.ps1 cannot be load
ed because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:2
+ . <<<< "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-VIToolkitEnvironment.ps1"
PS C:\Program Files\VMware\Infrastructure\vSphere PowerCLI>
通过在powershell里运行"set-executionpolicy unrestricted"解决. -- VIA
2. 我是在xp系统上安装的powershell 1.0, 在调用powershell的时候, 遇到了System.Management.Automation命名空间找不到的问题. 理论上这个 System.Management.Automation.dll 文件应该存在于:
"C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\"
目录下. 可惜没找到. 后来在
"c:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\"
目录下把这个dll直接copy出来, 引用后命名空间可用了. -- VIA
3. 写个小程序通过powershell打开VIServer连接的时候, 又遇上了一个问题:
The term 'connect-VIServer' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
这是因为没有加载VI snapin. 在脚本头加上这样一行就ok了:
Add-PSSnapIn VMware.VimAutomation.Core -- VIA




为了解决第一个错误,运行"set-executionpolicy remotesigned"比较好。
楼上, 多谢指点 :D 多多关照!