Run the script file from a virtual machine

Hello

I have a script (c:\script.ps1) I want to run on a virtual machine. Can someone tell me how to do?

When I want to run the single command on vm I follow these steps:

> > $cred = get-Credential

> > Invoke-VMScript - win1 VM - GuestCredential $cred - ScriptText "dir".

but I don't know how to put the script in a variable so that I can place it after the parameter - ScriptText.

PS Script is not on the virtual machine, it's on the computer I have installed PowerCLI.

LucD thanks for help

I managed to do this way:

$script = Get-Content - Path C:\script.ps1 | Out-string

Invoke-VMScript - win1 VM - GuestCredential $cred - $script ScriptText

without out-String I received the error "failed to convert System.Object [] to the System.String type.

Tags: VMware

Similar Questions

  • Deleting the same files of many virtual machines remotely

    Hi all

    I tried to delete the same file several virtual machines remotely using the following script PowerCLI:

    $a = Get - VM | %{

    foreach ($nic as $_.) Guest.Nics) {}
    Write-output $nic. IPAddress
    }
    }
    foreach ($i in $a)
    {$b = get-WmiOBJECT-query "SELECT * from CIM_DataFile where Name='C:\\test\\deleteme.exe'"-computername $i}
    $b.delete)

    }

    It works perfectly when I run the script on the host virtual machines while I am running the script PowerCLI. When I Connect-viserver to another host however and try to run the script, I get the dreaded "RPC server is unavailable error (HRESULT: 0x800706BA)" for Get-WmiObject.  Virtual machines don't have Windows Firewall and have all TCP/IP, RPC and WMI services started, so who could eliminate any possibility.

    I am also able to run other scripts that use the Get-wmiobject across all virtual machines such as scripts to change the DNS or Netbios name across many machines on different hosts.

    Any comments would be greatly appreciated and please feel free to comment if you know maybe other ways which can delete files on multiple virtual machines in any other way.  Installation PowerCLI to run the script locally on each host would be a laborious process to do.

    Thank you very much!

    Best regards

    To solve the problem with the quotes, you can use double quotes inside the string. Like this:

    «del "«c:\documents and settings\text.exe»»»

    Or you can use for the string single quotes and double quotes inside:

    "del"c:\documents and settings\text.exe"

  • Dual boot MacBook running Win as host, not to run the Mac partition as a virtual machine?

    Sorry if this has been requested a lot of times before, it was difficult to try to sift through responses to this particular configuration through research.

    I have a MacBook which double - start by training camp.  I generally run Windows but do have occasional need to pop in Mac.

    Is there a way to get my Mac running as a virtual machine in Windows partition?  I've seen a lot of discussion of the scenario opposed using Mac and Fusion, but not found on my installation.

    Thanks in advance for any help, especially if it's the ten thousandth time it was requested.

    Within the limits of your question, it is not supported by VMware.  That means that the only product from VMware that supports the legal vitualization of legally virtualisables versions of Mac OS X is VMware Fusion when run under Mac OS X on a Mac to processor Intel.

    In addition, if it's not Mac OS X Server 10.5, 10.6. 10.7 or Client Mac OS X 10.7, so he is not allowed by the Apple ALS and cannot therefore be discussed in these forums without violating the terms of use of the VMware community.

  • Need help updated the VMX file on several Virtual Machine

    All,

    Can anyone help with a problem I'm having?  Here is a brief explanation of what is happening and what we need to solve.

    Recently we found out that we need to add a line in the file VMX of several virtual machines.  In the past, I was able to do this, but would have cold start the virtual machine for the changes to take effect.  Starts cold won't be a problem, because we can program it.

    However, no one knows a way to add this line in the file VMX virtual machines in a cluster.

    Here's the line I need added:

    Devices.hotplug = "false".

    Here is a script that was used earlier (esx 3.0 days) to keep the VM tools updated on reboot.  At this point, if the virtual machine has been turned on, this change could not do through the UI.  However, this script worked to update the .vmx file and then we have cold reboots for the changes to take effect.

    Get-viserver - < Server > - < user > - < password >

    $viview = get-Cluster-name NOMCLUSTER | Get - VM | foreach-object {get-view ($_.ID)}
    $viview | {foreach-object
    $vmConfigSpec = new-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = new-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.afterPowerOn = 'True '.
    $vmConfigSpec.Tools.afterResume = 'True '.
    $vmConfigSpec.Tools.beforeGuestStandby = 'True '.
    $vmConfigSpec.Tools.beforeGuestShutdown = 'True '.
    $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle".
    $_. ReconfigVM ($vmConfigSpec)
    }

    The exact script can be found in Disable HotPlug

  • do I have to buy the new key to run the operating system on a virtual machine personal use? SOS. SOS...

    Hello

    I wanted to run vista on the same computer; but on a virtual machine. I wanted to know if I should buy a seprate key. I was perplexed because it is on the same computer at home. I wanted to use it for personal use as run the operating system on the virtual machine for programs to avoid viruses and use it kind of like a backup. I asked around only to meddle with the answers. Many people need to know the right answer to this question. Oh guys please keep this thread alive for others!

    Thank you

    Jamie

    Hello

    the rules of licensing are:

    One license = Installation and which includes computer

    the vista virtual machine installation will be a second installation requiring a second license of Vista

  • Location of the VMX file for a virtual machine

    My problem,

    I have a bunch of VM that names the real record of the VM and files below are NOT the same as the VM name shown at the VI appointed client. -J' it can't wait... makes more complicated

    I want to know is if there is a way to a virtual machine that is in inventory and get the path to his report and the real VMX path of query file, which I guess would give me the name of the data store and the record in the data store.

    My question for example:

    My - vma: (in VIclient)

    [myds0100]/web34/web34.vmx (because if I get off by accessing the site after clicking on 'my - vma' VM in viclient)]

    You can do

    Get - VM | Select the path Name,@{N="VMX"; E={$_. ExtensionData.Config.Files.VmPathName}}

    You could also have a look at the VIProperty called VmxDatastoreFullPath.

  • GUI: how to run the same command on multiple virtual machines at the same time?

    Hello

    Suppose we have several operations on multiple virtual machines (for example as updated virtual hardware, install vmtools - but it could be something else of course...).

    I would avoid clicking on each virtual machine (especially when we have hundreds of different groups).  It is possible to select sort

    (they are not side by side) and perform on a particular operation on all selected both?

    Hello

    If you use vCenter 5.1 + you can also try to use marking and assign tags on the items in the inventory.

    VSphere 5.5 Documentation Center - apply a label to an object

    Search for items by this tag.

    If you want to use PowerCLI 5.5, you can also search the inventory by this tag.

    Get-VM-Tag which lists all the virtual machines with which

    Here are some links for getting started with vSphere PowerCLI

    Back to Basics: part 1 - installation PowerCLI | VMware PowerCLI Blog - Articles from VMware

    vSphere PowerCLI Documentation

  • Create the alarm to run the script when migrating a VM

    Very well, I create an alarm that triggers a script that runs whenever a virtual computer is migrated automatically in a DRS cluster. I see in the API documentation that I could use the EventAlarmExpression - & gt; new (eventType = & gt; "VmMigratedEvent") (or maybe one of the other dealing with migration eventType). " The problem is that I don't see a way to be able to use a RunScriptAction with an EventAlarmExpression. It seems the only way is to use the RunScriptAction with a StateAlarmExpression. Here is a code snippet showing if all goes well I would do:

    My = $vmName ' name_of_vm;

    My $alarmScript = ' / usr/sbin/vm_migration_update.pl';

    My $vm = Vim::find_entity_view (view_type = & gt; 'VirtualMachine.

    filter = & gt; {name = & gt; $vmName}) ;

    My $alarmMgr = Vim::get_service_content() - & gt; alarmManager;

    my $alarm = Vim::get_view (mo_ref = & gt; $alarmMgr);

    My $alarmExpr = EventAlarmExpression - & gt; new (eventType = & gt; (' VmMigratedEvent');

    My $alarmAction = RunScriptAction - & gt; (new)

    script = & gt; $alarmScript

    );

    My $alarmTrigger = AlarmTriggeringAction - & gt; (new)

    action = & gt; $alarmAction,

    1. red2yellow = & gt; 1,

    1. green2yellow = & gt; 0,

    1. yellow2red = & gt; 0,

    1. yellow2green = & gt; 0

    );

    My $alarmSpec = AlarmSpec - & gt; (new)

    name = & gt; "Migrated VM."

    Description = & gt; 'Trigger to run the script then from VM migration',

    activated = & gt; 1,

    expression = & gt; $alarmExpr,

    action = & gt; $alarmTrigger,

    );

    My $newAlarm = $alarm - & gt; CreateAlarm (entity = & gt; $vm, spec = & gt; $alarmSpec);

    The problem is with the AlarmTriggeringAction. There is nothing to test with an EventAlarmExpression (i.e. the EventAlarmExpression does not provide States of red/yellow/green). So the question is, does anyone know how to set up an alarm that will run a script when an EventAlarmExpression is used. Specifically, I'd like to be able to run a script each time a virtual machine is migrated automatically in a DRS cluster. Pointers would be greatly appreciated.

    David

    Try this:

    C:\Windows\system32\cmd.exe C:\VMware\VMwareCLI\scripts\call_migrate_perl.cmd

    In fact, you can just run scripts perl like this:

    C:\Perl\perl.exe C:\scripts\migrate.pl

    Note: the commands are executed under 'System', not the user of the connection currently. If you don't see it visually. You can take a look at using Windows Task Manager if necessary.

    In addition, you can have parameters of placeholder that will be replaced before the "scripts" are actually executed.

    Good luck!

    Steve JIN, VMware engineering

    Creator of VI Java API: http://vijava.sf.net/

  • Cannot run the script generated with export Clip.

    I use AE CS6 and FCPX 10.0.7. I have imported the images in this way successfully before and have not changed or updated either of these programs since. Exporter of clip is up to date.

    Today, I created an XML of my calendar and trying to run the script generated from it, I get the error 'cannot run the script on line 22. WHEREAS"}

    I opened to the top of the script and 22 bed line editor ' comp [0] = {name: "Scenes of Kyle", w: 1920, h:1080, pasp:1.0000, hard: 39.7063, fps:23.9760, departure: 0.00001};

    Any help would be appreciated.

    The default is here:

    name: "Scenes of Kyle.

    For a shell script that reads as

    Kyle, scenes of s

    or be interpreted as noise and move the successive data so it would be interpreted wrongly. This is simply sloppy programming. It will have to be properly "escaped" to avoid the error:

    "Scenes of Kyle\".

    Contact the creator to fix his script and for the time being to use folder names that go without apostrophes...

    Mylenium

  • Script to create multiple virtual machines model works is not for the network adapter variable

    We are working on a script to create multiple virtual machines from a template. The script works fine, but when we try to include commands to set the NIC to a group of specific ports on a dvswitch script errors on. Here's what we have so far. This script (less network variables) works, but we would like to include the network configs in the script as well.

    -------------------

    This is the part of the script that configures the network/dvswitch adapter... but does not work properly.

    $myResourcePool = get-ResourcePool-name DQOL

    $dsName = get-Datastore-name "DQOL-DS01.

    $myTemplate = get-Template-name "DQVTemplate".

    $distributedSwitchPortGroup = get-VirtualSwitch-distributed - name "CVE-dvS04-Nexus - k 5 | Get-VirtualPortGroup-name '979-DQ-SHARED '.

    New-VM-name MyVM1-model $myTemplate - Networkname ResourcePool - $myResourcePool - OSCustomizationSpec $mySpecification $distributedSwitchPortGroup - Datastore

    (Get-$dsName data store)

    New-VM-name MyVM2-model $myTemplate - ResourcePool $myResourcePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    _____________________

    !!!!!!!  This part works, but without specifying a network/dvswitch... card!

    $myResourcePool = get-ResourcePool-name DQOL

    $dsName = get-Datastore-name "CVE-SAN-ISG-DS02-02ef.

    $myTemplate = get-Template-name "DQVTemplate".

    New-VM-name MyVM3-model $myTemplate - ResourcePool $myResourcePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    New-VM-name MyVM4-model $myTemplate - ResourcePool $myResourcePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    Here is the error we get:

    New-VM: all parameters can be resolved by using the specified named parameters.

    C:\Users\capuanoj\Desktop\Create-multiplevms-fromtemplate.ps1:6 char: 7

    + New-VM < < < <-name MyVM1-model $myTemplate - Networkname $distributedSwitchPortGroup - ResourcePool

    ePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    + CategoryInfo: InvalidArgument: (:)) [new-VM], ParameterBindingException)

    + FullyQualifiedErrorId: AmbiguousParameterSet, VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

    You cannot use the - model and Networkname - parameters of the cmdlet New - VM in a single order, because both are in different parameter sets. You must first create the virtual machine and then use the cmdlet Set-NetworkAdapter to change the portgroup of the virtual machine. As in example 4, assistance from cmdlet Set-NIC:

    --------------  Example 4 --------------

    C:\PS>$myNetworkAdapters = Get - VM | Get-NetworkAdapter-name "NIC 1.
    $myVDPortGroup = get-VDPortgroup-name MyVDPortGroup
    Together-NetworkAdapter NetworkAdapter - $myNetworkAdapters - $myVDPortGroup Portgroup

    Retrieves all network named "NIC 1" cards of all virtual machines and connects to the specified distributed port group.

  • Run the script FDM Essbase, no .bat files

    I want to run a script directly from FDM Essbase without needing to use a .bat file.
    I went to hollow post where calls MaxL scripts are discussed, but I have not found anywhere, there is a solution for sending a script to essbase.

    I have problems connecting to essbase using already existing and subsequently adapter configurations send an essbase script to the server. This is done for example in the Load event - where the essbase data are disabled. I would need assistance on how to implement this kind of soluition in the event script for example BefImport.

    Hi Nicklas,

    A couple of things to note.

    You must pass a 1 as the first parameter to use a file as a calculation script. Note that a calculation .csc script example files that are in your database and it's called AggMonth.csc you would spend in:
    Set objHWRerurn = API. IntBlockMgr.IntegrationMgr.PobjIntegrate.varCon.DataManipulation.fCalculate(1,"AggMonth")

    If you use 2 as the parameter to the fCaculate function, which means that the calculation script is a string, you can search for 'Essbase calculation chain' in the adapter to see how it works.

    If you really want to use a .maxl script and not an Essbase calc script you do not use the fCaculate function and will shout to essmsh.exe with parameters that does not use FDM adapter functions.

    PS You can also configure features of validation in FDM and assign scripts to those and then tell FDM you use 'file '. For the planning/essbase, it makes more sense to have just a script probably the method you follow.

    Kind regards

    John A. Booth
    http://www.metavero.com

    Published by: Jbooth on March 18, 2011 09:25

  • "Cannot run the script at line 1. File or folder does not exist. »

    Whenever I have start AfterEffects, I get an error as he is looking to find my recent projects.  The error is as follows: "unable to run the script at line 1. File or folder does not exist. "I haven't changed the location in one of my project files.  It's the same external drives that I use for months.  When I click on OK the same window opens several times and then finally the historic window opens completely blank and empty.  I am able to reopen projects however since the RECENT PROJECTS drop in the top bar.  It is a very strange and disturbing behavior.  In addition, I always use 13.7.2 because when I go to update it is impossible to connect and gives me this error.  I sat with Adobe support for an hour today, and we couldn't understand.  As I am in the middle of major projects, I decided to not update, but this error at startup is very worrying.  Someone has an idea of what could go wrong or how I can fix this?

    Thank you very much for your time.

    -Fredo

    Screen Shot 2016-07-06 at 7.21.26 PM.pngScreen Shot 2016-07-06 at 7.21.11 PM.png

    Ok!  Just got a response and an Adobe technical support solution.  The problem is that there is a problem with these versions of sequels (and I found the same problem in first to my horror this morning as well!) and the last couple Mac OSs.  The solution is to close the window "library".  It is then normally.  Apparently they fixed in the last update, but I found the same problem on my second computer, which has been updated.  Anyway, if anyone has this problem, close your cc library window.  Voila.

  • All files generated by a coil in sqlplus receive ownership of oracle: dba instead of the user of the BONE started sqlplus and run the script. There's a file with users owners of BONES of the coil.

    All files generated by a coil in sqlplus receive ownership of oracle: dba instead of the user of the BONE started sqlplus and run the script. There's a file with users owners of BONES of the coil.

    Script launched in until OS user 'A' on the 'A' server which launches sqlplus, then connects to a remote database through a service of tnsnames.ora as another user of the database and the results of this script are spoulées on the server "A".

    The file queued on the old server is written with rw-rw-r: read write user, group read the writing, reading and possession header that is the user of the OS. The file queued on the new server is written to rw-r-r user: reading writing, reading group, public reading and ownership oracle: dba.

    "" The user then has no privileges to modify the file and continue the process of transmitting the file, editing and deleting the file for the next set of commands. This allows us to keep the possibility to migrate to the new server we are unable to process orders.

    $ORACLE_HOME/bin/sqlplus - s user/password@prd1 @./script/CustomScript/R12_OM_UFPC-oracle.sql

    Background: old server running 4.8, Oracle 10.2.0.4 OEL

    New server running OEL 6.5, Oracle 11.2.0.4

    Tested so far:

    File and update umask to 0002 instead of 0022 is now generated as rw-r-r. However, the property is still oracle: dba.

    Update of ownershipt of $ORACLE_HOME/bin/oracle.exe of oracle: oracle (edi added the user to the oracle group) and chmod 6751 oracle.exe. This created several problems where crucial scripts, that is to say of sqlplus failed to run.

    Added! chmod 755 output.file.name - OS user 'A' is not allowed to change to mod.

    Added! command cp MV output file and that generated the file as a user of the operating system: oracle. It is a potential work around in case of emergency, but the developer would have to rewrite the countless scripts.

    Any ideas?

    I have reproduced the behavior of the old server and am able to spool a file via sqlplus under OS user. No changes have been made on the remote database server. All the changes have been on the new server hosting a small 11.2.0.4 database on a server running OEL 6.5 32 - bit OS.

    (1) removed the sticky bit $ORACLE_HOME/bin/sqlplus using chmod u-s, g-s, o - s suggestion of Billy ~ Verreynne

    (2) modified the main group for the 'oracle' user match the user operating system applications, while maintaining membership in the groups 'oracle' and 'dba '.

    -We are dealing with here EDI processes, so the Group was called edi.

    (3) modified property of the files tnsnames.ora and listener.ora for oracle: edi

    (4) restart the receiver

    (5) disconnect / reconnect

    Script runs as expected, the output file contains the correct ownership and permissions.

    Thank you all for taking a look and offering options.

    -Josh

  • I can't open the RAW files from my Nikon D800 (i.e. NEF files).  I use a Mac with Photoshop CS5 and El Capitan 10.11.2 version running.  I get a message "could not complete your request because the file appears to be a model of camera that is n

    I can't open the RAW files from my Nikon D800 (i.e. NEF files).  I use a Mac with Photoshop CS5 and El Capitan 10.11.2 version running.  I get a message that "could not complete your request because the file appears to be a model of camera that is not supported by the installed version of Camera Raw. Please visit the Camera Raw help documentation for more information. "Yet the Nikon D800 is on the list of supported devices.  Can anyone help?

    And temporarily disable the Gatekeeper by allowing downloads from anywhere, or your installer will be marked as 'damaged' because that CS5 is out before Gatekeeper and is not "signed" that is not approved.

  • Not possible to export a list of virtual machines that are created in the past 7, 30, 120 and 180 days since an imported csv file containing the date of creation of virtual machine

    Not possible to export a list of virtual machines that are created in the past 7, 30, 120 and 180 days since an imported csv file containing the date of creation of virtual machine. My questions is the correct statement to the variable: $VmCreated7DaysAgo: $_CreatedOn "-lt" $CDate7.

    # #SCRIPT_START

    $file = "C:\Users\Admin\Documents\WindowsPowerShell\08-18-2014\VM-Repo.csv".

    $Import = import-csv $file

    $VMCreatedLast7RDayRepoFile = "C:\Users\Admin\Documents\WindowsPowerShell\08-18-2014\Last7Days.csv".

    $start7 = (get-Date). AddMonths(-1)

    $CDate7 = $start7. ToString('MM/dd/yyyy')

    $VmCreated7DaysAgo = $Import | Select-object - property name, Powerstate, vCenter, VMHost, Cluster, file, Application, CreatedBy, CreatedOn, NumCpu, MemoryGB | Where-Object {$_.} CreatedOn - lt $CDate7} | Sort-Object CreatedOn

    $TotalVmCreated7DaysAgo = $VmCreated7DaysAgo.count

    $VmCreated7DaysAgo | Export-Csv-path $VMCreatedLast7RDayRepoFile - NoTypeInformation - UseCulture

    Write-Host "$TotalVmCreated7DaysAgo VMs created in 7 days" - BackgroundColor Magenta

    Invoke-Item $VMCreatedLast7RDayRepoFile

    # #SCRIPT_END

    You can use the New-Timespan cmdlet in the Where clause, it returns the time difference between 2 DateTime objects.

    An example of this cmdley

    New-TimeSpan-start (Get-Date). AddDays(-7)-end (Get-Date). Select days - ExpandProperty

    In your case, you could do

    Where {(New Timespan-démarrer ([DateTime] $_.))} CreatedOn) - end $start7). {7 days - gt}

    But beware of negative numbers.

Maybe you are looking for