Launch Perl within PS Console

Running Perl script with parameter from within Powershell Window

Whilst doing automated configuration of ESXi4.x I need to install hardware specific bundles for example HP CIM providers. Now the PowerCLI cmdlet Install-VMHostPatch does not recognise the offline bundle as valid as can be seen below.

[vSphere PowerCLI] C:\> Install-VMHostPatch -LocalPath G:\ESX\Bundles\ESXi410\hp-esxi4.1uX-bundle-1.0.zip
Install-VMHostPatch : 26/07/2010 11:09:50 AM    Install-VMHostPatch        Invalid patch archive: 'G:\ESX\Bundles\ESXi410\hp-esxi4.1uX-bundle-1.0.zip'.    
At line:1 char:20
+ Install-VMHostPatch <<<<  -LocalPath G:\ESX\Bundles\ESXi410\hp-esxi4.1uX-bundle-1.0.zip
    + CategoryInfo          : InvalidArgument: (G:\ESX\Bundles\...-bundle-1.0.zip:String) [Install-VMHostPatch], VimException
    + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_TryValidateUpdateLocation40_InvalidArchive,VMware.VimAutomati 
   on.ViCore.Cmdlets.Commands.Host.InstallVMHostPatch

Now I can run the vSphere CLI vihostupdate.pl to install this bundle, however a separate window is launched from the current Powershell window and closes. Which in it self is not a problem however what if there is an error? I simply do not have enough time to see if I have a syntax error in my command.

So how to run the perl script without launching a separate window?

First *.pl needs to be in the PathExt environment variable, once it is in there the perl script will output to the powershell window. So how do I do this? Here is a oneliner to do just that.

if (!($env:pathext.ToLower()).contains(".pl")) { $env:Pathext="${env:PathExt};.pl" }

Note: This setting only stays valid for the current powershell session.

Back to my original requirement to apply 3rd party offline bundles. Well now I have to ensure I have the correct amount of quotes to account for long files with space, parameters passed to the vihostupdate script and expansion of Powershell variables all at the same time. Below is what I came up with.

[string]$vmhostname="devesx1"
[string]$vmhostuser="root"
[string]$vmhostpwd="password"
perl.exe """C:\Program Files\VMware\VMware vSphere CLI\bin\vihostupdate.pl"" --server $vmhostname --username $vmhostuser --password $vmhostpwd --install --bundle G:\ESX\Bundles\ESXi410\hp-esxi4.1uX-bundle-1.0.zip"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.