Best way to encapsulate PowerCLI scripting

I want to write and use scripts that require commands PowerCLI. As long as they are run 'special' PowerCLI icon, all right. They'll run very well. However, I wish I could just run them from any command line, like this:

.\Create-TestingBoxen.ps1

Can I have the script itself call & ' C:\Program Files (x 86) \VMware\scripts\Initialize - PowerCLIEnvironment.ps1' itself, but that failure if my script is running on anything not to use standard install.

I might be able to find a standard registry key that will give me the installation location of the init script, but that still leaves a mess ungainly when the script runs. The init script prints a bunch of text color that serves a "in to PowerCLI.

Also, it is best if scripts do not let a bunch of stuff without report charged when they end. As near as I can tell, this strategy leaves all stuff loaded PowerCLI in regardless of the terminal used to run the script. I would like to be encapulated scripts.

All that's really standard stuff for scripts, so I think that a lot of people have understood this problem already. I am fairly new to Powershell scripts (with a lot of experience in * nix shell scripts), so I hope that there is just something obvious that I'm not. Otherwise, that things are ' All done to wrap your scripts so that they can be used anywhere PowerCLI is installed?

Hello, alficles-

If your scripts are usually autonomous, you shouldn't need to do all these calls to other init scripts.  In other words, if you don't try to use functions defined in the init script which you referred (like Get-InstallPath or LoadSnapins functions), you can just load the snapin (s) needed within your own script.

For example, if your script uses the standard, core VMware VimAutomation cmdlets, you can just have your script load the PSSnapin appropriate if it is not already loaded.  And to not let load/persistent PSSnapins, you can just have the script unload the PSSnapin given if it had to load the PSSnapin said.  Something like:

## start of script:  add PSSnapin if not already loadedif ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null ) {Add-PsSnapin VMware.VimAutomation.Core; $bSnapinAdded = $true}

## do all the good script stuff here##  stuff##  ...##  stuff

## at end of script, if given PSSnapin had to be loaded at start, unload it hereif ($bSnapinAdded) {Remove-PSSnapin VMware.VimAutomation.Core}

So, just load the PSSnapins script needs (if not already loaded) and unload at the end if the loaded script their.  Make sense?

Tags: VMware

Similar Questions

  • Best way to run a script from a script

    Hello world

    I'm looking for running a script from an After Effects script, so far, there is aftereffects.executeScript (scriptContent) who use eval to run the script. The problem is that it uses eval so it is not really sure and he is slower. So I would like to know what is actually used when we file-> Script-> Run script file.

    As seen in the Javascript tool Guide CC page 168 in the section QAnywhere Corss-DOM.

    aftereffects.executeScript(theScriptContent); // Doesn't work with a script which as comments AND the script has access to my scope
    

    In addition, if there are comments like / * * / or / * / in the script I want to run, it no longer works.

    So, what is the best way to run a script from a script?

    If you want to evaluate a whole script file, you can use $.evalFile (file, timeout) - see description in ESTK object model viewer

    To evaluate a bit of code, you can use eval, that's for sure.

    Xavier

  • Best way to schedule/run scripts third 3rd on an OEM customer?

    We currently use some 3rd party scripts on our monitoring systems.  Before launch us into monitoring OEM, we would simply install OEM, integrate existing monitoring script, and then maybe slowly migrate on.  These scripts are run several times daily through cron.

    Would it not be appropriate to migrate these courses as jobs on our OEM customers?  This would allow us to customize the calendars of the script (IE every 5 minutes), the report if these scripts fail, etc. ?

    Or is there a better mechanism to use?

    (This is for OEM 12 c)

    You can read the doc below:

    Using the system of employment and corrective measures

    In EM12c, you can schedule a job to run every n minutes/hours/days and select to receive notifications by email on the status of the job.

    Kind regards

    -Loc

  • What is the best way to deal with the events of Qml-components of java script or C++?

    Hello

    Please suggest which is the best way to treat the Qml-components signal in the manuscript of java or C++.

    can read contacts in javaScript?

    When you want to make things more complex: Yes.
    QT made it much easier for me as a java developer, bb, but you will need to learn some basics.

  • What is the best way to get a customized version # from an ESXi host?

    Each quarter, we generate a sequence of updates (including patches and security scripts) which are performed manually on our 5.0 ESXi hosts. I don't have an internet connection and so I have to do it this way.  I would like to be able to identify the last quarterly update that has been run on the vCenter servers and/or Client VI.

    Right now, I think adding the quarter, example 1 Q 13 on the DCUI message, then help PowerCLI, vCenter to retrieve the message DCUI, crawled and paste the quarter in the field host Annotations on vCenter.

    Kind of ugly, but I cannot find a cool way to get data like this outside of the host.  I don't want to rely on my user manually set to nothing, for example the field of Annotations on vCenter that is also subject to errors.

    I really want something that can also be seen on the VI Client, too, as the annotations are only on vCenter.

    I have ideas about the best approach to tackle this problem.

    Thank you

    Not sure if this is the best way, but that's what I ended up doing.   It feels like there should be a better way.

    I've updated my quarterly script to add the version number at the bottom of the file, / etc/vmware/welcome, whenever it is run on an ESXi host (e.g. myScript version: v1.0 Date: 04June2013).  This file appears under the banner DCUI.

    Then, I wrote a script powerCLI to roughly the following:

    foreach ($vmHostObj in Get-VMHost-name *) {}

    # Get the full message of DCUI in/etc/vmware/welcome

    $msgObj = echo $vmHostObj | Get-VMHostAdvancedConfiguration-name Annotations.WelcomeMessage

    # Convert a hash of a string table welcome message

    $msgTxt = echo $msgObj.Item ("Annotations.WelcomeMessage")

    # find the clue for the string containing my script information, which is at the end of the welcome message.

    # This is important because the substring below function will extract everything after the index.

    $idx = $msgTxt.IndexOf ("version myScript :")

    If ($idx - gt 0) {}

    $label = $msgTxt.Substring ($idx)

    Set Annotation - remarks on the entity $vmHostObj - CustomAttribute - value $label

    }

    }

    This replaces the Notes field for each host, one day I can go back and make it more user-friendly where it replaces the version leaving the rest of the field notes intact.

  • PowerCLI script to check the setting of syslog on a whole cluster?

    Hey guys,.

    I'm looking for a way to check the setting configured for syslog remote on a large cluster of ESXi. Is it possible to easily check by cluster?

    Thanks in advance,

    The following PowerCLI script will give you the servers remote syslog for all hosts in a cluster:

    Get-Cluster "MyCluster" | Get-VMHost | ForEach-Object {
      $VMhost = $_
      $VMHost | Get-VMHostSysLogServer | ForEach-Object {
        $Report = "" | Select-Object -Property VMHost,SyslogServer,Port
        $Report.VMHost = $VMhost.Name
        $Report.SyslogServer = $_.Host
        $Report.Port = $_.Port
        $Report
      }
    }
    

    Best regards, Robert

  • Best way to build the same ESX hosts

    Hi, I need to build 4-6 ESX hosts are configured identically. (Same groups of ports, NTP settings etc..) All hosts will use the same brand/model/hardware configuration)

    I think kickstart server and a load of scripts PowerCLI would be the best way to do this, but I don't him did not before.

    Can you recommend the best way to do that, or no matter what links?

    Thanks in advance

    PS. The customer only paid for the license of the company,(not enterprise Plus), so I can't use Host Profiles)

    Are kickstarts way to go.  However, if you have business + licenses you can use the profiles of the host.

    Here's what I've used to help build my kickstarts

    http://blog.laspina.ca/ubiquitous/automating-vSphere-ESX4-host-installations

    http://www.VMware.com/PDF/vSphere4/r40_u1/vsp_40_u1_esx_vc_installation_guide.PDF

    ... also, everything I do not use this, it is very well implemented

    http://www.jasemccarty.com/blog/?p=571

    .. .and finally

    http://www.ivobeerens.nl/?p=509

  • Best way to generate signals of activation (square wave) with my 9401 on my 9022?

    Hi, I tried seriously over the past two days to find the best way to do it. I am trying to generate a very precise square wave, controlling the duty cycle and frequency, with the OID on the 9401 in testbed cRIO 9022.

    I have a VI that is theoretically able to do this, but whenever I try to go above 5 Hz or more, duty cycle and frequency becomes inaccurate (I have watch on an oscilloscope), various a lot too for my needs. I have a feeling that this is caused by my addiction on the calendar software controlled, with errors at the time (of the ms order) accumulate as they get processed and the signal is sent. I have attached a piece of code that illustrates the basic idea of what my VI have in them.

    I have avoided the square wave generators integrated because I could never work to satisfaction, but I can work with them so that will solve my problems. Selection structures and cases prevent the user to exaggerate their inputs. Unwaited so the loop was just to test.

    I'm running the 9022 as target in real time, but also tried to run in the FPGA and I was able to produce much more accurate signals using FPGA VI square wave, displaying a Boolean variable, but I couldn't see the best way to get double precision variables to work with everything (and I want more precision than variables FXP enabled clock 40 MHz).

    I feel there is just a mistake in my approach here. I've seen other discussions where people throw around using meters to edge of the test bench to produce a square wave, and I see the example screws as Gen dig pulse - continuous Train, I'm not sure if initially these screws DAQmx for my situation (eg. How to identify my counters, because they are clearly not Dev1/ctr0 by default in these examples)

    Thank you

    Dealing with the representation of Point fixed and all is a reality for LabVIEW FPGA<= 2011="" programmers.=""  you="" might="" build="" a="" small="" sub="" vi,="" such="" as="" the="" one="" attached,="" to="" encapsulate="" the="" frequency="" calculation,="" thereby="" abstracting="" the="" conversion="" formula="" and="" fixed="" point="" data="" type.=""  you="" can="" adjust="" the="" properties="" of="" the="" floating="" point="" input="" control="" to="" accept="" only="" valid="">

    This implies the series VI void on the host of the RT, and not on the FPGA target.  So, you also need nodes in the Palette of the FPGA Interface to send PWM fixed Point RT frequency to the FPGA.  The complete solution of frequency may resemble the following.  It is common for FPGA programmers to build a collection of thesesub screw, that make up the API for hardware.

    Note that 40 MHz is hard-coded.  For increased flexibility, consider making the FPGA clock rate an entry to the Subvi with a default value of 40 MHz.

    -Steve

  • Best way to distribute the Drivers of Instruments LabVIEW.

    Hello

    I'm trying to stick to the standards described just that:

    However, I see clearly what is the best way to distribute LabVIEW instrument Drivers, except that I need to be compliant with these standards are on the IDNET (Instrument network drivers).

    Here are a couple of questions, I'm not really sure of their responses:

    • Is it safe to use a .NET dll and make calls?
    • Is this really hide the block diagram? With the passwords in the drivers
    • Can we prevent the change
    • In my situation several devices (or let's say modules can be controlled by means of a communication), so basically I could be an instrument for many things drivers.,.
    • Can I use some OOD? In order to control the equipment with methods and set properties and encapsulate the tricks of communication in the classes, some equipment could be considered are inherited from other (most recent example), or it is totally prohibited by the above guidelines?
    • What is the type of specification build more appropriate: library packages or other? If packed library, how to handle the first version created problem at the opening of the lib with the new version of LabVIEW then?
    • How to deal with the copyright thing, I have to copy and paste the copyright on both before and on the block diagram Panel?
    • Is this copyright enough: "Copyright (c) . All rights reserved"?

    Ehouarn wrote:

    Hello

    I'm trying to stick to the standards described just that:

    However, I see clearly what is the best way to distribute LabVIEW instrument Drivers, except that I need to be compliant with these standards are on the IDNET (Instrument network drivers).

    Here are a couple of questions, I'm not really sure of their responses:

    • Is it safe to use a .NET dll and make calls?
    • Is this really hide the block diagram? With the passwords in the drivers
    • Can we prevent the change
    • In my situation several devices (or let's say modules can be controlled by means of a communication), so basically I could be an instrument for many things drivers.,.
    • Can I use some OOD? In order to control the equipment with methods and set properties and encapsulate the tricks of communication in the classes, some equipment could be considered are inherited from other (most recent example), or it is totally prohibited by the above guidelines?
    • What is the type of specification build more appropriate: library packages or other? If packed library, how to handle the first version created problem at the opening of the lib with the new version of LabVIEW then?
    • How to deal with the copyright thing, I have to copy and paste the copyright on both before and on the block diagram Panel?
    • Is this copyright enough: "Copyright (c) . All rights reserved"?

    But unsure about 1) (2) and 3) definitely are a no go if you want your library to be distributable through the network ID. The standard only allows dll in which are really developed in C, but you also need to distribute the C code as far as I understand.

    OOP isn't necessarily a problem.

    Packed library is certainly not something you want to do. They work only in the version of LabVIEW in which they were created. You hate when you decide to go with the packaged libraries requests arrive for other versions of LabVIEW and your drivers are high on all the forums of discussion as being a pain in the ass to use.

  • What is the best way for foglight consume a webservice

    I hope that this is has not been replied that a bazillion times and if it is please send me the link I'm open to that.  What is the best way for foglight consume a Web service and respond with an alarm if the response from the Web service is not what is expexted.

    for example, calls Foglight webservice to acme.com/areuup and he responds with correct status in json format process.  If it does agree return, then foglight must send alerts to correct individuals.

    Thank you

    Kaleb

    in the end, we have used a perl script to capture the webservice and treat it and tables configuration.  Here is what has been written and created an agent custom.

    I apologize to all those who find the bulky comments, but it's my edition of journal of the script. I removed the comments once the script has been published and used.

    ===

    #! / usr/bin/perl

    #############################################################

    # Author: Kaleb J. Albee

    # Depandancies: SOA webservice

    # Engineers: Marc and Manu

    # Date: 28/02/2013 perl: (v5.14.2) built for x86_64-linux-gnu-thread-multi

    # Operating system: Linux 3.2.0 - 29-generic eam-ops-test #46 - Ubuntu SMP Wed Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

    #############################################################

    use strict;

    use warnings;

    use Try::Tiny;

    use SOAP::Lite;

    use SOAP::WSDL;

    Use Time::Local;

    My = @soaenvs ('BSE - dev', 'BSE test', 'BSE-scene', 'BSE');

    # parameters: $_ [0] receives a call of SOAP client object.

    #

    void toStr {return $_ [0] == 1?} 'up': 'down' ;}

    void getBusResults {}

    # $_ [0] will be the $client spent

    # create a different buses SOAP connection.

    my $result = $_ [0]-> (getMessagingEngineHealth)

    # arg0 is used to set the setting for what is expected on the soa web service.

    SOAP::Data-> name (arg0 => $_ [1]));

    # $_ [1] will be the bus happened in

    return (Lk ($result) "started" eq? 1: 0);

    #return $result;

    }

    # Start sampling.

    My $curTimeStamp = "";

    my $count = 0;

    Print "LdsEsbBusHealth5\nSTART_SAMPLE_PERIOD\n TABLE";

    foreach my {$soae (@soaenvs)

    my $client is SOAP::Lite-> service ("put the url of the webservice here.");.

    $count ++;

    # create an object to inspect objects. My $insp = Data new::Inspect->; Download the time stamp for this.

    my ($sec, $min, $hr, $day, $mon, $year) = localtime;

    # format the year correctly for useage.

    My $curyear = 1900 + $year;

    # the hand to the fglam agent fields at the tables.

    My $soacei = getBusResults ($client, "messaging.000 - CEI.esb.BUS");

    My $soaapp = getBusResults ($client, "messaging.000 - SCA.APPLICATION.esb.Bus");

    My $soasys = getBusResults ($client, "messaging.000 - SCA.SYSTEM.esb.Bus");

    $curTimeStamp = ' $curyear$ MON$ day$ hr$ min$ s ";

    Print "SoaEnv.String.id=$soae\n";

    Print "CeiBusNum = $soacei\n";

    Print "AppBusNum = $soaapp\n";

    Print "SysBusNum = $soasys\n";

    Print "CeiBusStr.StringObservation.obs =". toStr ($soacei). "\n";

    Print "AppBusStr.StringObservation.obs =". toStr ($soaapp). "\n";

    Print "SysBusStr.StringObservation.obs =". toStr ($soasys). "\n";

    Print "Daterun.StringObservation.obs=$curTimeStamp\n";

    If ($count<=>

    Print ("NEXT_SAMPLE\n");

    }

    } {$soae foreach (@soaenvs) #.

    Print "END_TABLE\n";

    Exit 0;

    ===

    I hope this helps someone out there!

    Bravo!

  • the best way to deal with the changed values maskMode?

    Hi people

    I just found out that the values listed for maskModes have changed between CC14 and CC15 who broke most of my scripts of masking.

    IE MaskMode.ADD in CC14 has the value 6413 but CC15 is 6813.

    What is the best way to deal with this? is there a simple solution or what I need to check the version of AE which is used and adjust from there?

    is there a direct way to access the name ie "MaskMode.ADD" instead of the value?

    Thanks... /JL

    To get the string maskMode by the current mask, you can loop through all the values possible maskmodes and stop when you click on:

    for (var k in MaskMode){
        if (myMask.maskMode === MaskMode[k]) break;
        };
    // at this stage k is the maskMode string (eg: "ADD")
    

    Xavier

  • What is the best way to design a gallery of images which can be seen on all devices

    I'm trying to find out about the best way to convert an existing gallery in a sensitive Gallery to be seen on all devices. I have about 200 images. I know about the phones, the number of images would kill most of the data plans.

    1. what would be the optimal number of images to use on small devices (phone)?

    2. is it possible to add additional images as the largest becomes peripheral (Tablet, laptop, office, TV)

    3. are there plugins or scripts to facilitate this?

    Just try to pass to sift through all the possibilities before dive page and having to redo again and again, rather than once.

    Thank you

    John

    Burst your gallery in bite size pieces - spread over several pages.

    The optimized use of thumbnail images that do not kill data plans.

    Put your images in actual size in a modal window Viewer.  In this way mobile users have a choice of whether to view pictures.  See the link below for more details.

    Bootstrap Modal + Carousel Gallery - http://alt-web.com/

    Nancy O.

  • best way to add a CURVES layer

    Hi all

    I am writing to you the best way to add an ArtLayer with a script.

    I already know that it is possible to add an Artlayer, and then change the layer.kind to the TEXT property.

    But unfortunately it is not possible to add change this property to LayerKind.CURVES.


    Here is an example

    /**
     * Function to add a layer to a Document
     * @param {LayerKind} layer_kind, the type of the layer (CURVES, TEXT, SELECTIVECOLOR)
     * @param {Document|LayerSet} [obj = app.activeDocument] the obj which contains the new layer
     * @return {ArtLayer} layer the added layer
     * @todo add a better test to check if layer_kind is an enum of LayerKind
     * @toto add control the layer is background or not
     * @todo https://forums.adobe.com/thread/1601245
     */
    my.add = function (name, layer_kind, obj) {
    
       if (obj === undefined) {
       var obj = app.activeDocument;
      }
    
       if (typeof layer_kind !== 'object') {
       throw {
       name: 'InvalidArgumentError',
       message: 'you must enter a valid value for the param layer_kind [CURVES, TEXT, SELECTIVECOLOR, etc.]',
       fileName: $.fileName,
       lineNumber: $.line
       };
      }
    
       var layer = obj.artLayers.add();
    
       layer.kind = layer_kind;
       layer.name = name;
    
       return layer;
    
    }
    

    So the only way to add different type of layer should use listener Action Script?

    I'm a little confused, because it would be much better to be able to change the layer.kind property.

    In advance, thank you very much for your help.
    Best account.

    Don't forget your does not deal with Adobe here it is the user forums.  If you want changes made to Photoshop scripts that you need to address Adobe please use Photoshop family customer community and submit a suggestion.

    Adobe DOM is limited without Manager Action code via ScriptListener Photoshop script script is not very useful because limited methods of model DOM of Adobe Photoshop. Many Photoshop features are not supported and the supported features can be supported in a limited way.

  • What is the best way to get a SVG file generated from After Effects?

    What is the best way to get a SVG file generated from After Effects?

    Is there a script to do this? I use the SVG file directly in my work. I did research online, but find that it has no native support of EI to achieve.

    I found some scripts online, but they convert output Adobe AE to the JSON file. Is there something similar available for the SVG file?

    Thank you

    AE makes pixels not vectors, so it's not possible.

  • Create jobs that runs a powercli script every day at 20:00

    Hi all

    I'm looking for a way to add a powercli script to cron or schduler so that it runs every day at 20:00 say... I found average windows wrt link below

    http://social.msdn.Microsoft.com/forums/SharePoint/en-us/e63d0776-b4aa-4ab6-885c-a41fd0c83a7c/create-job-that-runs-a-PowerShell-script-every-day?Forum=sharepointgeneralprevious

    Is there better way that this can be done for powercli as well?

    Thank you

    AFAIK, except if you have a few programming specifialised run SW, Windows Scheduler did a good job.

    BTW, Alan has also made a post on this, see running a scheduled task PowerCLI

Maybe you are looking for