Define custom tools VMware of PowerCLI scripting?

Hello

I wonder if it is possible, from PowerCLI, define scripts custom in VMware Tools. These are the scripts that run when you suspend/resume/etc...

I looked in the docs and online and here and could not find anything. Do you need to use the VIX api for this?

Thank you

Mike

http://communities.vmware.com/servlet/JiveServlet/download/38-20628/vExpert_logo_150x75.jpg

There are 2 options:

(1) you re-use the existing files of bat on reviews

(2) you specify a .BAT file

For the 2nd option you will require, as pointed out by William, the VIX API.

But for the first method you can do it with the current generation of PowerCLI

This script changes the content of the file by default poweroff BAT.


$vmName = 
$powerOffBatName = "poweroff-vm-default.bat"
$getProgPath = "echo %ProgramFiles%"

$newPowerOffBat = @"
Rem New PowerOff script
dir
"@

# Store new bat file locally
Set-Content -Path ($env:temp + "\" + $powerOffBat) -Force -Value $newPowerOffBat

$vmImpl = Get-VM $vmName
$vm = $vmImpl | Get-View

# rem Get credentials
$guestCred = Get-Credential -Credential "guestuser"
$hostCred = Get-Credential -Credential "hostuser"

# Get the content of %ProgramFiles% on the guest
$progPath = (Invoke-VMScript -GuestCredential $guestCred -HostCredential $hostCred `
     -VM $vmImpl `
     -ScriptText $getProgPath -ScriptType "Bat").Trim()

# Set the path of the file
$powerOffBatPath = $progPath + "\VMware\VMware Tools\" 

# Remove the read-only attribute
$unsetRO = 'attrib -R "' + $powerOffBatPath + $powerOffBat + '"'
Invoke-VMScript -GuestCredential $guestCred -HostCredential $hostCred `
     -VM $vmImpl `
     -ScriptText $unsetRO -ScriptType "Bat"

# Copy the new file
$destFile = $powerOffBatPath + $powerOffBat
Copy-VMGuestFile -Source ($env:temp + "\" + $powerOffBat) `
     -Destination $destFile `
     -GuestCredential $guestCred `
     -HostCredential $hostCred `
     -LocalToGuest -VM $vmImpl

# Set the read-only attribute
$setRO = 'attrib +R "' + $powerOffBatPath + $powerOffBat + '"'
Invoke-VMScript -GuestCredential $guestCred -HostCredential $hostCred `
     -VM $vmImpl `
     -ScriptText $setRO -ScriptType "Bat"

# Activate the option to run a script
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.beforeGuestShutdown = $true
$vm.ReconfigVM_Task($spec)

Note that these default files BEATS all are set to read-only, so that changes to the script that assigns and assigns it back afterwards.

To make the script work on different flavors of Windows, it gets the path of the environment variable %ProgramFiles% % on the guest.

And to make sure that the script defines also the option of script run VMware Tools for action from extinction.

It should be relatively simple to change this for all the other options like suspend, restart, resume...

I would like to know if it's a little what you are looking for?

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • PowerCli Script to change the VM Options?

    Is it possible to use PowerCli to change the options for a virtual computer?  Specifically, I would like a PowerCli script to select control of boxes on a virtual machine under Options-> VMware Tools-> advanced settings until the VMware Tools are upgraded during the feeding cycle and the time is sync would be.

    Thank you

    JD

    Here's what we use if you want to pull from a text file.

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    #$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
    $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
    
    Get-Content -Path "C:\names.txt" | %{
        (get-vm -Name $_).Extensiondata.ReconfigVM($vmConfigSpec)
    }
    
  • Flash Cs5 JSFL findObjectInDocByName do not work in the custom tool

    When I run this script from Adobe Flash Professional * fl.findObjectInDocByName () as a simple command

    var nameToSearchFor = "instance01"; 
    var doc = fl.getDocumentDOM(); 
    var results = fl.findObjectInDocByName(nameToSearchFor, doc); 
    if (results.length > 0) { 
      alert("success, found " + results.length + " objects"); 
    } 
    else {  
      alert("failed, no objects named " + nameToSearchFor + " found"); 
    }
    

    everything is ok, but when I want to add this code to custom tool I get errors.

    Script error in function mouseDown

    function configureTool() {
    theTool = fl.tools.activeTool;
    theTool.setToolName( "Sew" );
    theTool.setIcon( "Sew.png" );
    theTool.setMenuString( "Sew" );
    theTool.setToolTip( "Sew" );
    theTool.setOptionsFile( "Sew.xml" );
    theTool.setPI( "shape" );
    
    }
    
    
    function activate(){
    fl.trace("ACTIVATE");
    }
    
    
    
    function mouseDown(){
    
    var nameToSearchFor = "instance01"; 
    
    var doc = fl.getDocumentDOM(); 
    
    var results = fl.findObjectInDocByName(nameToSearchFor, doc); 
    
    if (results.length > 0) { 
    
      fl.trace("successfound"); 
    
    } 
    
    else {  
    
      fl.trace("failed"); 
    
    }
    
    }
    
    
    function deactivate() {
    fl.trace("End");
    }
    

    Why?

    I have foud solution

    To write

    FL.trace (FL.configURI)

    go to this location JavaScript search folder > ObjectFindAndSelect.jsfl

  • Collection for the PowerCLI scripting requirements

    Someone at - it a good model that helps you organize information, gathering process when you go to the management or to a customer to get for scripts and automation requirements that they want to do?  Y at - it a Web page or a book that puts this kind of thing in a structured methodology or at least one practical how to guide?

    For example, what kinds of questions should I go to make sure that I understand any of my script is supposed to do and help the management or the customer understand what THEY want to do, and get a consensus agreement on the functional requirements for my powerCLI script?

    Your suggestions of entry, welcome masters strategies.

    This question is not really unique for PowerCLI scripting, but all scripts/programs, to write (for yourself or for a customer |).

    And of course, there are always the classic answer "it depends".

    If it is a small task that you write yourself, the requirements are pretty obvious.

    Most of the time, you have the requirements in your head, but it does not have to write in schematic form.

    When you write for a customer, by definition be more formal (I guess).

    An article I like, is the Introduction to gather our creative use cases and requirements published in the Code review.

    Take a look.

  • Can write us "PowerCLI Script" to get the details of card RAID HP (Firmware & Driver)?

    Can write us "PowerCLI Script" to get the details of card RAID HP (Firmware & Driver)

    For example: native ESX command below shows desired output for me.

    But we needed equality PowerCLI ESX command below script

    # cat/proc/driver/cciss/cciss0

    cciss0: HP Smart Array P400i controller

    Board ID: 0x3235103c

    Firmware version: 7.22# cat/proc/driver/hpsa/hpsa0

    hpsa0: HP Smart Array P410i controller

    Board ID: 0x3245103c

    Firmware version: 5,70

    Driver version: HP HPSA driver (v 5.0.0 - 17vmw)

    The extracted following PowerCLI you will get server and type of controller, firmware version and the hpsa/Smart Storage Array controllers driver version based of:

    Get-VMhost | Sort | Select Name, Model,@{N='Controller Type'; E={(Get-VMHostHba -VMHost $_ | ? {$_.Model -imatch '.*(hpsa|smart).*'}).Model}},@{N='Controller Firmware'; E={($_.ExtensionData.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | ? {$_.Name -like '*hpsa*firmware*'}).Name}},@{N='hpsa Driver Version'; E={($_.ExtensionData.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | ? {$_.Name -like '*scsi-hpsa*'}).Name}} | Format-Table -Autosize
    

    The sample output:

    
    Name                     Model                Controller Type   Controller Firmware                           hpsa Driver Version----                     -----                ---------------   -------------------                           -------------------esxihost1022.local    ProLiant DL380 G6    Smart Array P410i    HP Smart Array Controller HPSA1 Firmware 6.40    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1023.local    ProLiant DL380 G6    Smart Array P410i    HP Smart Array Controller HPSA1 Firmware 6.40    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1024.local    ProLiant DL380 G6    Smart Array P410i    HP Smart Array Controller HPSA1 Firmware 6.40    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1033.local    ProLiant DL360p Gen8    Smart Array P420i    HP Smart Array Controller HPSA1 Firmware 5.42    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1034.local    ProLiant DL360p Gen8    Smart Array P420i    HP Smart Array Controller HPSA1 Firmware 5.42    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1041.local    ProLiant DL380 G5    Smart Array P400    HP Smart Array Controller HPSA1 Firmware 7.24    VMware scsi-hpsa 5.0.0-17vmw.500.0.0.469512 2011-08-19 01:58:59.000esxihost1042.local    ProLiant DL380 G5    Smart Array P400    HP Smart Array Controller HPSA1 Firmware 7.24    VMware scsi-hpsa 5.0.0-17vmw.500.0.0.469512 2011-08-19 01:58:59.000esxihost1160.local    ProLiant BL460c Gen8    Smart Array P220i    HP Smart Array Controller HPSA1 Firmware 5.22    Hewlett-Packard scsi-hpsa 5.0.0-40OEM.500.0.0.472560 2012-08-24 21:04:51.000esxihost1161.local    ProLiant BL460c Gen8    Smart Array P220i    HP Smart Array Controller HPSA1 Firmware 5.22    Hewlett-Packard scsi-hpsa 5.0.0-40OEM.500.0.0.472560 2012-08-24 21:04:51.000
    
  • I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly

    I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly.

    I tried to use for the function FolderByPath below, but don't know how to use it and have worked. Please help me in this.

    Function Get-FolderByPath {}

    < #.

    . Records of recovery SYNOPSIS by giving a path

    . DESCRIPTION the function will retrieve a record by its

    path. The path can contain any type of leave (folder or)

    Data Center).

    . Author NOTES: Luc relaxing

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . PARAMETER separator

    The character used to separate the leaves in the

    path. The default value is ' / '.

    . EXAMPLE OF

    PS > Get-FolderByPath-path ' Datacenter/Folder1/Folder2 ".

    . EXAMPLE OF

    PS > Get-FolderByPath-path "Folder1 > Folder2"-separator ' > '

    # >

    (param

    [CmdletBinding()]

    [parameter (Mandatory = $true)]

    [System.String []] ${Path}.

    [tank] ${delimiter} = ' / '.

    )

    {in process

    If (((Get-PowerCLIConfiguration).)) DefaultVIServerMode - eq "Multiple") {}

    $vcs = $defaultVIServers

    }

    else {}

    $vcs = $defaultVIServers [0]

    }

    {foreach ($vc to $vcs)

    {foreach ($strPath in $Path)

    $root = get-file-name of the server data $vc centers

    $strPath.Split ($Separator) | %{

    $root = get-inventory-name $_-location $root - server $vc - NoRecursion

    If ((Get-stocks-localisation $root-NoRecursion |)) Select--ExpandProperty name)-contains "vm") {}

    $root = get-inventory-name "vm" - location $root - server $vc - NoRecursion

    }

    }

    $root | where {$_-is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|% {}}

    Get-file-name $_. Name - location $root. Parent - Server $vc

    }

    }

    }

    }

    }

    You can try to retrieve the object file by steps as well.

    Something like this for example

    $folder = get-data center-name 'LTX01-G8 | Get-file-name "LTX-servers | Get-file-name "LTX servers 0000 - 0299. Get-file-name Linux

    I guess the first qualification in your path was the data center.

  • When I click on Define Custom Shape, I get an error message: "could not complete your request because of a program error."

    I use Photoshop CC 2014. When I click on Define Custom shape, there is an error box that says: "could not complete your request because of a program error."  How can I fix it or work around it? I have looked on the internet for answers, but could not find any solution to this. The custom shape tool is 99% of what I use!

    Well, now it works. It was a particular path that generated the message. Other forms custom records.

  • GUI for the PowerCLI scripting

    Someone knows a software or tool that generate the GUI for the PowerCLI scripting?

    There are a few, Sapien is free and it's called PrimalForms Community Edition.

  • The package PowerCLI script in the Windows executable file / install

    What are the options for packaging / embed PowerCLI script in Windows. EXE file? I would like for several departments to be able to run and collect information from the script without having direct access to the code. This would ensure that the code has been correctly run without modification.

    I know that PowerCLI will be available on these systems, searching for the PowerCLI is not necessary.

    I read that the Primal Script has this ability, but I want a solution that is free and easy to use, if possible.

    If it is not an executable file, maybe even a file coded which makes it difficult for a layman to make changes.

    Thanks in advance for the help!

    I used a similar function of Johan Akerstrom in the past (since I don't have the community installed Extensions).

    See his post Powershell script to generate an executable from a powershell script .

    For this one, I know there is no problem with parameter passing.

    Take this example script

    param(
    [parameter(Mandatory = $true)][string[]]$server)
    
    [void][system.reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
    Add-PSSnapin -Name VMware.VimAutomation.Core
    
    Connect-VIServer -Server $server[windows.forms.messagebox]::Show("Connected to " + $defaultViServer.Name)
    $VM = Get-VM[windows.forms.messagebox]::Show("I counted " + $VM.Count + " guests")
    
    Disconnect-VIServer -Confirm:$false
    

    Note that the script uses Windows Forms to the output data.

    You create the EXE file as follows. I recorded the example script under DoExeTest.ps1

    PS C:\Scripts >.\DoExeTest.ps1 new-PSExecutable
    Script source file: C:\Scripts\DoExeTest.ps1
    Output executable: C:\Scripts\doexetest.exe

    And when you run this, it displays 2 message boxes, one with the name of the vCenter and the other with the number of guests, the script is located in the vCenter.

    C:\Scripts>doexetest.exe 'Site '.

                  

  • PowerCLI Script to the report on the failed VM jobs

    I figured out how to report on the events of VM (get-vievent), but no has no stains of VM. If a snapshot of the virtual computer fails, sometimes it never connect the events of the VM, but lists an error on the display of tasks. We are trying to monitor the clichés failed since its part of our backup solution.

    I was looking for a way to report these tasks/failure of events in a daily report, or simply add to the daily report of amazing Alan Renouf that we use.

    does anyone have any suggestions? For an example, see the attached screenshots. See how, in the view tasks, you have mistakes, but in the view of events, there is no errors.

    Any help would be great. Thank you!

    Jeff

    PowerCLI Script to the report on the failed VM jobs

    I figured out how to report on the events of VM (get-vievent), but no has no stains of VM. If a snapshot of the virtual computer fails, sometimes it never connect the events of the VM, but lists an error on the display of tasks. We are trying to monitor the clichés failed since its part of our backup solution.

    I was looking for a way to report these tasks/failure of events in a daily report, or simply add to the daily report of amazing Alan Renouf that we use.

    does anyone have any suggestions? For an example, see the attached screenshots. See how, in the view tasks, you have mistakes, but in the view of events, there is no errors.

    Any help would be great. Thank you!

    Jeff

    Hi Jeff

    I had exactly the same need to identify stereotypes having failed and drilled until SDK and LucD suggestions (thank you) to encode the following lines:

    $vmlist = Get-VM |sort Name
    
    foreach ($guestname in $vmlist)
    {
        $hours = 48 # Number of hours back
          $tasknumber = 999          # Windowsize of the Task collector
    $taskMgr = Get-View TaskManager
    
    # Create hash table. Each entry is a create snapshot task
    $report = @{}
    
    $filter = New-Object VMware.Vim.TaskFilterSpec
    $filter.Time = New-Object VMware.Vim.TaskFilterSpecByTime
    $filter.Time.beginTime = (Get-Date).AddHours(-$hours)
    $filter.Time.timeType = "startedTime"
    
    $collectionImpl = Get-View ($taskMgr.CreateCollectorForTasks($filter))
    
    $dummy = $collectionImpl.RewindCollector
    $collection = $collectionImpl.ReadNextTasks($tasknumber)
    while($collection -ne $null){
    $collection | where {$_.DescriptionId -eq "VirtualMachine.createSnapshot" -and $_.EntityName -eq $guestName} | %{
    if ($_.State -eq "Error") {
            write-host $_.EntityName
            write-host $_.StartTime
            write-host $_.State
            }
        else {
        }
    }
    $collection = $collectionImpl.ReadNextTasks($tasknumber)
    }
    $collectionImpl.DestroyCollector()
    
     }  
    

    This script displays the name of the virtual machines which met with an instant failure in the last 48 hours (a variable, you can change)

    This is just the beginning, because I want to count the shots failed and identify virtual computers that have more than 2 in 2 days

    Feel free to alter it at will.

    Enjoy

    Eric

  • How to start a PowerCLI Script automatically

    I'm looking for a way to automate a PowerCLI script start.  For example, starting with the most basic scripts such as:

    Get-VM-name MyVM

    I want to have a file that I can click on my desktop that starts PowerCLI, running connect-VIServer and connects to my server, gives the appropriate credentials to connect, then running my

    Get-VM-name MyVM

    script.  It could be a batch (.bat) windows file that would start with powershell and run a .ps1 file, in the process of passing all the arguments appropriate for authentication, etc. or another strategy.

    Take a look at this article.  Step 3 review the batch file to create and your authentication options.

    http://blogs.VMware.com/vipowershell/2009/09/how-to-run-PowerCLI-scripts-from-vCenter-alarms.html

    Dave

    VMware communities user moderator

    Now available - vSphere Quick Start Guide

    You have a system or a PCI with VMDirectPath?  Submit your specifications to Officieux VMDirectPath HCL.

  • How can I use a custom tool easy to machine the same LabVIEW is the basis on average DC - RMS VI

    I use a cRio 9024 and read PWM with an analog input card 9205.  It was suggested that I use the basis on average DC - RMS VI to convert the voltage of the PWM signal into an analog signal (effective value) for use in my system.  The problem is that the 9024 can use LabVIEW models (it's VxWorks). I work through the device a custom tool easy and I wonder if someone can guide me in the right direction.

    I am running Veristand 2014, cRio-9024, 6modules, and run the scan engine.  It seems that's the reason why I can't read analog voltage (starting a PWM signal) since the signal is running at 200 Hz and the Scan Engine runs at 500 Hz.   I tried to avoid making a custom device or an FPGA and found a work around using the 9401 in counter mode.  I can get the numbers that I need, that's how I'm heading at the moment.  I would like to custom device approach, but not this sprint.

  • Cannot find custom tool MxbCodeGenerator after VS2005-&gt; conversion of 2008

    I'm limping into c# and recently converted a c# VS2005 project with Measurement Studio 2009 to VS2008 the wizard of conversion VS.  Since then the VS2008 project has been building and running great, until today when I tried to change my VisaTask1.mxb Assistant.  When I did, I got a warning on the build in saying:

    "Cannot find the custom tool 'NationalInstruments.MeasurementStudio.Tools.DotNET.MxbCodeGenerator' on this system."

    I am sure that the MxbCodeGenerator must be on the system somewhere.  In my project, I have work references to NI.Common, OR. UI, OR. USER INTERFACE. WindowsForms and NOR. World.  Someone know how I can find this MxbCodeGenerator tool again?  Without him my VisaTask1.cs code generated automatically cannot be updated.

    Thank you

    Penny

    Frederic,

    It worked!  Thank you very much.  I just added the "." 2008"as you suggested and now my VisaTask1.cs is updating again.

    These discussion forums are just the greatest thing since sliced bread.

    -Penny

  • Disable / lockdown 'create a custom tool '.

    Im doing a custom install via the "Adobe Customization Wizard DC", the deactivation of all sorts of things.

    All set up in the work of the wizard, except turning off the tool 'create custom tool '.

    I checked the box for the 'create custom tool' off, and after installation it also added the registry key. See

    [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Adobe\Adobe Acrobat\2015\FeatureLockDown\cAcroApp\cDisabled]

    "a0" = "CertificatesApp."

    'a1' = 'CustomUIApp. '

    "a2" = "SendAppFull."

    But when I opened Acrobat after installation (and reboot) its always showing and usable.

    Is there something else that needs to be done to disable this tool?

    Well I just found the answer... The customization tool adds the incorrect registry value.

    The Customization Wizard adds the value "CustomUIApp". It should be "CreateCustomUIApp".

    Found the answer here, where theres a value name list of all applications of theire register:

    tion of the http://www.adobe.com/devnet-docs/acrobatetk/Tools/AdminGuide/Planning.html#Tools-configura

  • Why Define Custom Shapes does not work because of a program error?

    I was selecting a path, to create a custom shape, and I got a program error message, that States "cannot complete the Define Custom Shape command because of a program error." How can I fix it?

    Post edited by: Trevor Dennis [confusing typo in the subject line corrected]

    In fact, I checked and found a pre-announcement that clarifies the issue. I'm the Photoshop classroom in a book and created the paths using the subtraction of the form. After this post, which will result in a program error, that the procedure would be to use exclude shapes that overlap. I was going to try this anyway. Beautiful when books are wrong... Nothing has been said in the paper on the creation of a new fill layer

Maybe you are looking for