In the Developer forum there was an interesting post called Resources for folks new to the vSphere Web Services SDK. Now unfortunately the Hello World guide was (again) only aimed at Java programmers.
Although PowerCLI is nearing perfection, you sometimes will have to go to the SDK methods and properties to make your script go that extra mile. Since I know, from first-hand experience, that the first steps in the SDK are not that simple for PowerShell programmers/scripters I decided to start a series to make the SDK more accessible for the PS people.
The first entry in the series is a simple one. It will take the Java sample form the above mentioned document and show you how to do the same thing in PS.
Make sure that you first read the Hello World document since it explains some key concepts on SDK programming.
Notice how simple the PS script is compared to the Java sample in the document. The major reason for this is that the PowerCLI Team did a marvelous job in predicting what you and I would need and packaged a lot of the dreary stuff in their cmdlets.
# Establish a session with the vCenter or ESX/ESXi server
# If no user/password is passed, the session will be set up for the current user
Connect-VIServer -Server MyvCenter
# The Get-View cmdlet has shortcuts for some of the well-known entry points
$serviceInstance = Get-View ServiceInstance
# On SDK objects we can invoke methods. As a sample I use the CurrentTime method
# Terminate the session
Line 4 : this is where you connect to the web service port and establish a session
Line 12: call the CurrentTime method. Notice the difference how SDK methods are called and how the parameters are passed. In this case the empty parenthesis indicate there are no parameters passed.
Like I said, a small sample. But it contains some key concepts for using the vSphere Web Services SDK. And it shows how a lot of the hard work was already done for us by the PowerCLI Team.