Problem running script PowerCLI

Hi all

I am very new to PowerCLI and I'm looking for someone who can help me with a PowerCLI script I'm running. I found the script online created by someone named Ben on Geekynetworks below.

When I try and run the script it-error during the New - VM:

New-VM: A positional parameter cannot be found by accepting the argument '-'.

C:\VCBScripts\clonetest.ps1:18 char: 8

Here is the script, can someone tell me what's in it?

Thanks in advance!

}

#To allow script to be run as batch job
add-pssnapin VMware.VimAutomation.Core

#declare array of VM names to clone
$src_vm_names = @("VM_1", "VM_2")

#connect to server
Connect-VIServer "vcenter" -User username -Password password

#Get current date in YYYYMMDD format
$date = get-date -uformat "%Y%m%d"
  
foreach($src_vm_name in $src_vm_names){

  $src_vm = Get-VM $src_vm_name

  #create a new clone of the VM
  New-VM -Name ($src_vm_name+"_clone_"+$date) -VM $src_vm -Datastore "remote_datastore" -VMHost "remote_host" -notes $date

  #Permanently delete all clones older than 7 days
  $clones = get-VM ($src_vm_name+"_clone_*")
  $expirydate = Get-date (Get-date).addDays(-7) -uformat "%Y%m%d"
  foreach($clone in $clones){
  if($clone.notes -lt $expirydate){
  Remove-VM $clone -DeletePermanently -confirm:$false
  }
}

}

He should be fine with the add-pssnapin, you have there, moreover, is not to choke on the Get - VM cmdlet that you run earlier, which shouldn't be a problem.

Make sure that you run in a 32 bit Powershell. The cmdlet New - VM (like one handful of others) will work only in a 32-bit Ppowershell. See:

https://www.VMware.com/support/developer/PowerCLI/PowerCLI51R2/powercli51r2-releasenotes.html

The following features of PowerCLI are supported only on 32-bit versions of Windows PowerShell.

New-OSCustomizationSpec and Set-OSCustomizationSpec

New-VM and Set - VM (only when it is used to apply customization specifications)

When running against vCenter Server or ESX/ESXi versions prior to version 5.0, the following PowerCLI functions are supported only on 32-bit versions of Windows PowerShell.

Invoke VMScript

Copy-VMGuestFile

New-VMGuestRoute, Get-VMGuestRoute and Remove-VMGuestRoute

Set-VMGuestNetworkInterface and get-VMGuestNetworkInterface

Together-hard drive (only when used for resizing the partitions of comments drive)

If you run just 'powershell.exe - file path\filename.ps1' of a cmd on a 64 bit OS, it will run the 64-bit default Powershell.

Run 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe leader path\filename.ps1' to call a 32 bit Powershell.

Tags: VMware

Similar Questions

  • Run scripts PowerCLi PowerCli console?

    Is it possible to run scripts PowerCLi PowerCli console?

    I want to use the batch with PowerCli orders orders... and I'm stuck on adding entries PowerCli keyboard console.

    You don't need the parameter of hard disk, the hard disk is passed through the pipeline of the cmdlet Get-disk hard.

    If the virtual machine has more than 1 hard drive, you use a Where clause to select the hard drive you want.

    Get-disk hard - VM "MV0857-gastela" |

    where {$_.} Name - eq "Hard Disk 2"} |

    Together-hard drive - CapacityKB 20000000 - confirm: $true

    You can call PowerCLI cmdlets, but be sure to connect all first.

    Something like this for example

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile  "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1"  -command "connect-viserver MyVC | out-null; Get-VM"
    

    Have you set the execution policy for PS?

    Make one

    Get-ExecutionPolicy

    To change you could do

    Game-ExeecutionPolicy RemoteSigned

    Just do it once.

  • Ayuda... run script PowerCli 5.1 en problemas con

    Gurus,

    Currently me encuentro developing UN laboratorio in el cual tengo than run a script en 5.1 PowerCli y don't me permite realize run del mismo en the imagen is muestra el error.

    Error_Script.png

    Of photos gracias for the help.

    ESE error're por una funcion no defined.

    El script en Cuestión're del lab troubleshooting workshop, is the funcion is defined in a profile of powerShell.

    If estabas in el course, the problem can be that you hayas con identified a usuario aren't el del dominio.

  • Try to understand the problem of script PowerCLI

    I'm a Beginner PowerShell CLI rank, but it has been on my list of things to get my head around for awhile, so I was playing with it for a week or two and have managed to solve most of the problems with the search, but for now I'm adapting a PowerCLI script I met a personal project to automate the creation of a vLAB and I don't understand not the problem well enough to be able to properly research could do with a pointer if possible.

    The script that I started with is http://poshcode.org/?show=1547

    The part of the code that I have problems with is line 25 in the original code that is:

    $rpool = for ($i = 0; $i - lt $vmhost.length; $i ++)

    If I run just this line from a prompt, I get the same error that is displayed below:

    [vSphere PowerCLI] C:\ > $rpool = for ($i = 0; $i - lt $vmhost.length; $i ++)
    Lack of closure ")' in the expression."
    On line: 1 char: 22
    + $rpool = for ($i = 0; < < < < $i - lt $vmhost.length; $i ++)

    I found that if I omit the "$rpool =" then this line of code executes, but then I can't use the results (even if I concede that someone who knows what they might be able to!) )

    So, as I understand it well enough to make this code work?

    The rest of the script is adapted to my where I created virtual machines from scratch rather than models, environment more I deal with three hosts but except that it is essentially the same.

    Pointers appreciated!

    (I would have commented on the site hosting the original code, but I couldn't find all the means to do so).

    Kind regards

    Paul

    For me, the command returns the numbers from 0 to 6, all as you would expect. It seems that there is something in your PowerShell session that prevents the statement to run correctly. Looks like you have redefined the command to something else. Maybe an alias or function.

  • Problem running scripts with Oracle Test Manager (MTM)

    Hi all!

    I am facing a problem to run any test in OTM.
    I'm adding scripts that I created in OpenScript (and which take place in perfect inside) but running in Test Manager fails.
    To be more precise, I even created a very simple script for the case in which I open the browser, navigate to an existing page (for example www.fmstocks.com/fmstocks - like documentation for example) and then I close the browser.
    What is happening is that the test fails after a few seconds. In the report results, summary of Script, it there a failure result to give Total iteration:

    + Object "/ web:window[@index='0" [or @title =' subject: empty '] "+."
    + did not action: +.
    + < name of message = "Navigate" > < parameter WindowIndex = '0' > +.
    + < / parameter > +.
    + < parameter Url = "http://www.fmstocks.com/fmstocks" > +.
    + < / parameter > < / Message > +.

    This is the same result that I get in any script I run (with different Url of course).
    I tried to alternate some settings in the Manager (Tools-> system) systems and change my OTM server, I've seen in a thread. I found that if I write as a user name and password to my windows or my OTM username and password (instead of JMSAdmin I see is the default user name) when I run the test simply never stops!
    To be clear, I just started using OATS. All the foregoing is done with the default settings after installation. OpenScript works fine but I need OTM so that I can perform several set of test scripts.

    Any help is appreciated!

    Hello
    You must first set back the remote system OTM to JMSAdmin / the_pwd_you_supplied_during_installation
    Then, you must stop the Windows Service called "Oracle Application Testing Suite Agent Service" and put it in the manual.
    Then, you start the agent from the command line
    C:\OracleATS\agentmanager\bin\AgentManagerService.exe - c C:\OracleATS\agentmanager\bin\AgentManagerService.conf (something like that according to the installation path).

    Let us know if it is ok then.

    JB

  • problem running script powershell bigbrother

    Hello!

    I'm trying to run a powershell script of big brother

    but nothing works...

    I added the script .ps1 to the external list restartted the client, without going

    I made a batch file to run the script and added to the external list and not go also.

    When I run either manually the script works... and my output file is written to the c:\BB\ext dir.

    is there a way to get this race?

    also when I run manually my file is picked up by the customer, but do not see the column appear on the web page.

    Note that there are other external systems running and those working OK. (one is a vbcripts and one is a .exe)

    I opened it and content

    The file is encoded in unicode. BB is not like that. Download the script to write to a text file of pain.

    ... | Out-File -Encoding "UTF8" ...

  • If for many of us become "run script" which is the original computer is running slowly... Why there is no one who knows why? If it's an ongoing why problem person has for the fixed?

    ITI usually occurs during playback of facebook, but has also happened while browsing on the net... This script is running? Any clue that the script is running it is causing the computer running slowly... Close script or let it run... .It lets you stop up to what I've changed the page but now keeps acsking every minute of fw making it imposible to continue with anything because it keeps freezing for about 30 seconds before asking if you want to continue running script... there is nowhere to ask what script runs just if you want to stop running... She has nothing to do with rogers... because now rogers continues to tell me it has to be close to cause of a problem, he met

    I bet that the people running Windows 7 with IE9 do not have this problem. If you are running XP, you cannot run any data more recent than IE8.

    Another problem is that people who post on this problem (including yourself) don't bother giving us important information such as what version of IE they run or the specifications of the computer (including the speed of the processor and the amount of RAM).
    Internet Explorer isn't the best browser in the world. I suggest that you run Google Chrome and then see if these Facebook games works:
  • Problems running JavaScript despite correct settings

    For some reason any, since I have updated to version 3.6 of Firefox, JavaScript does not work anymore.

    I checked the help files existing who asked me to check the Options in the Tools menu.

    Here are my settings, which should work, but aren't:

    1. on the content tab, 'Enable JavaScript' is checked.
    2. under Advanced options, the following are checked:

        a) Move or resize existing windows
        b) Disable or replace context menus
    

    Theoretically, this should work, but doesn't. Simply do not run scripts. You can provide any assistance is greatly appreciated.

    Sincerely,

    Robert Hieger

    This has happened

    Each time Firefox opened

    == I've upgraded to version 3.6 and now also 3.7.

    Thanks for your post, Wolfgang
    I think I'll go to Opera, until Firefox fixes some problems...

  • Definition of Orchestrator to execute a script PowerCLI

    What is the best way to implement Orchestrator to run a powerCLI script?

    Hello TheVMinator,

    Here are the first two ways that come to mind for me:

    1. VCO run under Windows - use the 'command' to fall at a command prompt, and then run your scripts PowerCLI from the vCO Server (you can use the method described in this article to access the object of the control: How to execute a PERL Script from a vCenter Orchestrator Workflow)
    2. Install the PowerShell plug-in, configure WinRM, then run your PowerCLI scripts on the remote host that you configured via WinRM (reference: seamless integration with PowerCLI and PowerShell plugin |) VMware vCenter Orchestrator Blog - VMware Blogs)
  • After 4.1 update, 1 host 'Error while running script control of health' - what to check next?

    I had an ESXi 4 update 1 host, I used the Update Manager to upgrade to 4.1.  To join the cluster, I get a red mark and the host State

    "HA agent on contains an error: error when running script control of health."

    Two hosts in a separate cluster do not have the same question.

    So far, I have

    Reconfigured HA

    HA HA/Enabled disabled for the cluster

    Restart management agents

    Server restarts

    Put the server on another cluster

    .. .the all result in the same error.

    Any ideas?

    I am also trying to solve this problem, and although I have not found a solution, I started to create an article documenting what I found regarding this error. I think I'm very close to a solution.

    UPDATE: I found the solution! Read the article below:

    (Solved) VMware HA fails after upgrade to ESXi 4.1

    http://www.paulscomputerservice.com/articles/article.php?id=183

  • The problem of Script root.sh - ora.asm and ASM and Clusterware battery failed

    People,

    Hello. I want to install Oracle 11 g RAC 2 using 2 VMs (rac1 and rac2) whose BONES are Oracle Linux 5.6 in VMPlayer according to the website http://appsdbaworkshop.blogspot.com/2011/10/11gr2-rac-on-linux-56-using-vmware.html

    I'm installing network infrastructure. On step 9/10 - run script /u01/app/grid/root.sh for 2 virtual rac1 and rac2 machines.

    After running root.sh rac1 successfully. I run root.sh in rac2 and get an error like below:



    [grid root@rac2] #./root.sh
    Run the script root.sh from Oracle 11 g...

    The following environment variables are defined as:
    ORACLE_OWNER = ora11g
    ORACLE_HOME = / u01/app/grid

    Enter the full path of the local bin directory: [usr/local/bin]: usr
    Copying dbhome to usr...
    Copying oraenv to usr...
    Copying coraenv to usr...


    Creating/etc/oratab file...
    Entries will be added to the/etc/oratab file according to the needs of
    Assistant configuration database when a database is created
    Finished to turn the generic part of the root.sh script.
    Now root product-specific actions will be performed.
    2012-03-05 16:32:52: analyzing the host name
    2012-03-05 16:32:52: verification of superuser privileges
    2012-03-05 16:32:52: user has superuser privileges
    Using the configuration settings file: / u01/app/grid/src/install/crsconfig_params
    Create the trace directory
    ADD LOCAL MODE
    Creating OCR keys for the user "root", "root"... privgrp
    Successful operation.
    Adding to inittab demon
    CRS-4123: Oracle high availability Services started.
    starts ohasd
    CRS-4402: the CSS daemon has been started in mode exclusive, but found a CSS daemon that is active on node rac1, number 1 and ends
    An active cluster was found at the exclusive start, start to join the cluster
    CRS-2672: attempt to start 'ora.mdnsd' on 'rac2.
    CRS-2676: beginning of "ora.mdnsd", the successful "rac2"
    CRS-2672: attempt to start 'ora.gipcd' on 'rac2.
    CRS-2676: beginning of "ora.gipcd", the successful "rac2"
    CRS-2672: attempt to start 'ora.gpnpd' on 'rac2.
    CRS-2676: beginning of "ora.gpnpd", the successful "rac2"
    CRS-2672: attempt to start 'ora.cssdmonitor' on 'rac2.
    CRS-2676: beginning of "ora.cssdmonitor", the successful "rac2"
    CRS-2672: attempt to start 'ora.cssd' on 'rac2.
    CRS-2672: attempt to start 'ora.diskmon' on 'rac2.
    CRS-2676: beginning of "ora.diskmon", the successful "rac2"
    CRS-2676: beginning of "ora.cssd", the successful "rac2"
    CRS-2672: attempt to start 'ora.ctssd' on 'rac2.
    Start action for octssd abandoned
    CRS-2676: beginning of "ora.ctssd", the successful "rac2"
    CRS-2672: attempt to start 'ora.drivers.acfs' on 'rac2.
    CRS-2672: attempt to start 'ora.asm' on 'rac2.
    CRS-2676: beginning of the 'ora.drivers.acfs' on 'rac2' succeeded
    CRS-2676: beginning of "ora.asm", the successful "rac2"
    CRS-2664: resource 'ora.ctssd' is already running on "rac2.
    CRS-4000: Start command has failed, or completed with errors.
    Return code of 1 (256) of control: / u01/app/grid/bin/crsctl start resource ora.asm - init
    Beginning of the resource ' ora.asm - init ' failed
    Could not start ASM
    The Oracle Clusterware boot failure battery
    [grid root@rac2] #.



    As seen above, the output at the end of the exit
    (1) beginning of resource ora.asm - init failed
    (2) could start ASM
    (3) could start Oracle Clusterware battery

    The runInstaller is in the first VM rac1. My question is:

    Any folk that understand how to solve the root.sh script in problem rac2 (3 fails to ora.asm, ASM and Clusterware battery as stated above)?


    Thank you.

    Please check there is no firewall don't exist:

    Try this as:
    root.sh fails on the second node

    Note MOS:

    Grid 11 GR 2: root.sh fails to start the Clusterware on the second node due to the firewall on the private network [981357.1 ID]

    Infrastructure 11.2.0.2 grid or upgrade installation may fail because of the requirement of multicast [1212703.1 ID] (most probabily this problem)

  • Error: BT Yahoo is not available due to a long-running script. How can I remove it?

    Original title: a long-running script

    Why constantly to make the message-' BT Yahoo is not available due to a long-running script.

    How can I remove it?

    Why constantly to make the message-' BT Yahoo is not available due to a long-running script.

    How can I remove it?

    a. on the Tools menu, click Internet Options.

    b. on the Advanced tab, click to select the checkbox disable the script debugger .

    c. click OK

    Error message: "a script on this page slows down Internet Explorer runs slowly.
    http://support.Microsoft.com/kb/175500/en-us

    How to resolve script errors in Internet Explorer on Windows computers

    http://support.Microsoft.com/kb/308260

  • I frequently get a pop up that says "' web page addresses do not cause of long-running script." "

    * Original title: pop ups

    I frequently get a pop up that says "' web page addresses do not cause of long-running script." "  It's maddening.

    It's all web sites that do, or just a specific or both? If its just one or two sites, try them as 'compatibility mode' - http://windows.microsoft.com/en-US/internet-explorer/use-compatibility-view#ie=ie-11

    If this does not help, it occurs to these sites if you run IE (assuming you're using IE) "mode without modules? ( [Internet Explore (No. Add ons)])

    If still no joy, then see if anything in this article allows --- https://support.microsoft.com/en-us/kb/308260#cause it is a long read but has a few things to try for script errors in Internet Explorer.

    The default base heal - use another browser like Mozilla Firefox - https://www.mozilla.org/en-US/firefox/new/

  • Problem running windows 10 to date for windows 7 Home premium 64-bit reference error code 08C 1800103 - 089002

    Problem running windows 10 to date for windows 7 Home premium 64-bit reference error code 08C 1800103 - 089002

    Could not update windows 7 Home premium service pack 1 for windows 10.

    I tried windows update. all updates are installed except win 10 update that comes up with unexpected error

    Please be aware, even if you do not get the Windows 10 app, you can always download Windows 10 as one. ISO file, create a bootable copy and update your system.

    See the instructions: How to download official Windows 10 ISO files

    Task of pre-required

    When you make significant changes to your computer for example updated operating system, you must always back up. See the links to resources on the backup by clicking the link for each version of Windows you are using: Windows XP, Windows Vista, Windows 7, Windows 8/8.1

  • Computer will not play my games such as those offered on FB, it keeps giving me an error running script

    My computer will not play my games such as those offered on FB, it keeps giving me an error running script, how can I solve this?, I can get on my fb, but not play my games.

Maybe you are looking for

  • Widgets on Droid Motorola

    I have the original Droid, but today, I put my hand on Droid 2 a friend... I love the bike Widgets! Is it possible to get them on the original Droid? My contract is not for me to get a new phone for about a year.

  • Cannot access a shared folder

    I have a network that uses a multude of different types of computers with different operating system, but most of the positions are Win XP or Win 7.  I am able to access a drive on the part of all but one.  The error I get is "the specified network n

  • Connecting 2 HP printers via Ethernet?

    Hi, new to the forum. Noticed the badge of 'Day of the Expert' on the HP site and thought it would be a good place to ask. Trying to give as much detail as possible. My apologies in advance if the message appears long I wonder if someone can provide

  • best way to add and change the menu all programs without turning off UAC?

    I just download HJsplit, as someone has sent me a video file into segments to overcome the limitations of attachment size. HJsplit doesn't require installation, but UAC is actually prevents me from adding it to the start menu. What would be the 'prop

  • Error of work on screen display will stop HP 2000-329WM