PowerCLI for 3 VMs at once.

I'm working on a great script, and I can't wrap my head around it.  I want to get the names of some virtual machines, but I want to be able to get the VMS in groups of 3, it could be 2 or 4, I just arbitrarily chose 3.  My ultimate goal is to export the virtual machines, but I want to their section, so I'm not under a great export at the same time.

So if I have 12 VMs, I want to get the first 3, export them, and then the next 3, export them and so on.

I realize that it can not always be 12, or a number which divides by 3, but I see that if I use Select-Object and select - top 5 of something that has only 3, it seems to work without any errors, so I'm not too concerned in making sure that the number is divisible by a number.

I tried something like this:

#$MyCount was already populated with five names VM

$CountComplete = $null

$CountComplete = @)

While (($Mycount | sort) - don't ($CountComplete | sort)) {}

$MyCount |  Select - 3 first | Get-Unique

$CountComplete += $Mycount

}

#$CountComplete += $Mycount

I know the above does not work, but I wonder if this is the right way?

Try something like this

I placed a few numbers in the $test table, but it could be VirtualMachine objects, the logic remains the same.

$test = 1,2,3,4,5,6,7,8,9,10

$start = 0

$step = 3

While ($start - the $test. Count) {}

Write-Output "handling $($test [$start...). ($start_+_$step_-_1)]) »

$start += $step

}

Tags: VMware

Similar Questions

  • PowerCLI for 'Not' VMs in a folder

    I am trying to retrieve a list of virtual computer with the exception of a select few names I want to accomplish this in DOES not receive the names in a certain folder.

    I tried this example:

    Get - VM | where {$_.} Name - don't (Get-Data-Center "someDataCenter" |) Get-file "SomeFolder" | Get - VM)}

    I realize that I could take the long way around and record the names of the virtual machines in a txt and then get back them with something like:

    Get - VM | where {$_.} Name - only (type c:\folder\file.txt)}

    But I want to know how logically the action the other direction.

    In addition, and this excited me was really until I completely failed him... I tried this:

    $vms = get - VM

    {Foreach ($vm to $vms)
    {Switch ($VM)}
    (Get-Datacenter "MyCenter" |) Get-file test. Get - VM) {}
    default {$exclude += $_.} Name}
    }
    }
    I tried to accomplish VMs not getting NOT another way, and I didn't want to wait to 'write' list the names of virtual machine, so I thought that I could save by default as a variable called $exclude and continue to add each VM name on it.
    What happened was that I have this long with each VM set name variable... so if I had 2 VMs named 'Test' and 'Test1', the variable $exclude would show this:
    PS C:\ > $exclude
    TestTest1
    Each individual letter would be a table element, $exclude [0] would be the letter "T" Test and not the name VM 'Test '.  Thanks for any help, and I hope that I have explained clearly.

    Maybe something like that? :

    #Omits parent folder names that match nameoffolder1 or foldername1
    Get-VM | where-object {$_.Folder -notmatch "nameoffolder1|foldername1"}
    #OR this which omits any vm w/ a parent folder matching the string nameoffolder
    Get-VM | where-object {$_.Folder -notmatch "nameoffolder"}
    

    Post edited by: Zsoldier

  • I have Acrobat Standard XI and recently downloaded CD Player for a specific use. Reader became my default for open PDF files once it has been installed. How can I get Acrobat Standard to be once more my fault?

    I have Acrobat Standard XI and recently downloaded CD Player for a specific use. Reader became my default for open PDF files once it has been installed. How can I get Acrobat Standard to be once more my fault?

    Hi nancye22519208 ,

    Please right-click on any PDF on your system, then go to properties > under general, you will find "opens with". Here you will see 'change' option, by clicking on it, wil give you a window from which you can choose the Acrobat Standard XI as a default for PDF files.

    Kind regards

    Christian

  • Cannot download - VMware vSphere PowerCLI for tenants

    Hi people,

    I'm not able to download VMware vSphere PowerCLI for the R2 version of tenants i.e. 5.1. Go to the page cannot be displayed.

    Please check.

    Kind regards

    Rajesh

    VMware vSphere PowerCLI for tenants

    Seems to work for me from this link.

    Perhaps a local cache in your browser problem, or a problem of Akamai in your area?

  • TO_DATE for use with only once

    I need to take strings such as ' 12:30 ' and convert them to the format HH24.» When I try using TO_DATE I get an error this date format picture ends before converting all of the input string. The statement that I used for the test is:
    select to_date('12:30 PM', 'HH24:MI') from dual
    Is there a good way to do this?

    Thank you!

    Hello

    If you want to read a date in a format and display it in a different format.
    Use a format when you read (with TO_DATE) and a different format when you view (using TO_CHAR).

    For example:

    SELECT  TO_CHAR ( TO_DATE ( '12:30 PM'
                       , 'HH:MI AM'
                     )
              , 'HH24:MI'
              )
    FROM     dual
    ;
    

    This has actually nothing to do with "to_date for use with only once": the same answer would apply if one or both formats include year, month or day to (or instead of) hours and minutes.

  • Using PowerCLI for VM disk Stats

    First of all - it's really a message to LucD (I know from previous aid tends to prowl this forum ), just thought I'd share, as is all the useful info and any idea LucD at will without doubt be useful for all.

    Hi LucD,
    First of all - thanks for a great selection of posts on Reporting for Powershell vSphere - well worth the time and a have read for anyone.
    I'm certainly not a good PowerShell - but I was able to understand and make changes to my profit - so I thought I would share my findings and ask a few questions.
    With your script as a basis - I was able to reach the following which SHOULD let me look at all VMs in VC one statistics collect virtual disk in time for VMS different discs, (IOPS / s, Throuput and latency) I use VC 4.1 and and NFS storage attached, I believe that these statistics are OK but would have your insight on this.
    I am very pleased with the script - but he needs more tests on a valid site, rather than my region little test, but I'm sure that from a point of view 'PS' there is more efficiency to win.
    First of all - is it possible to get all the statistics at a time-, rather than to make 6 calls per VM? (I'm also sure that the ' += ' a stat the following may not be ideal)
    Also - is there a way can control the output to the CSV file, it seems to put the columns in order any, he loves and layout does not appear to be linked to the order of a group object? Can it be controlled so I can have the entries 'value' and 'unit' next to each other
    ?
    Any insight and assistance would be appreciated, and I hope that others will give it a try and let me know if it works for them too.
    Thanks again for the inspiration and the vision that made me this far
    Tony.
    ESX 4.1, VC 4.1, 2.0 options, PowerCLI 4.1.1
    # Main Variables
    $sVCentre = "IP VC.
    $sVCUser = "administrator@domain".
    $sVCPwd = "password"
    $strVMWildCard = «*»
    $strCSVName = "Stats-AvgVMDiskWriteStatsWorkingday.
    $strCSVLocation = "c:\". »
    # define the start and end times for a day's work.
    $today9am = (get-Date-time Minute 9 - 0 - 0 second)
    $today5pm = (get-Date-time Minute 17 - 0 - 0 second)
    $intStartDay = - 1
    $intEndDay = - 1
    # Begin script
    #Connect to the CR
    Connect-VIServer $sVCentre - $sVCUser of the username-password $sVCPwd - ea silentlycontinue
    $arrVMs = get - VM | WHERE-object {$_.} Name - like $strVMWildCard}
    foreach ($strVM to $arrVMs)
    {
    Write-Host "get stats for:" $strVM.Name
    Write-Host "'-Assembly of latency of writing Stats" "
    $stats += get-Stat - $strVM - Stat virtualDisk.totalWriteLatency.average entity - start $today9am. AddDays ($intStartDay) - finish $today5pm. AddDays ($intEndDay)
    Write-Host "'-bringing together reading latency statistics '"
    $stats += get-Stat - $strVM - Stat virtualDisk.totalReadLatency.average entity - start $today9am. AddDays ($intStartDay) - finish $today5pm. AddDays ($intEndDay)
    Write-Host "'-Assembly Stats ARE Ops / s reading" "
    $stats += get-Stat - $strVM - Stat virtualDisk.numberReadAveraged.average entity - start $today9am. AddDays ($intStartDay) - finish $today5pm. AddDays ($intEndDay)
    Write-Host "'-writing ARE Ops / s Collator Stats" "
    $stats += get-Stat - $strVM - Stat virtualDisk.numberWriteAveraged.average entity - start $today9am. AddDays ($intStartDay) - finish $today5pm. AddDays ($intEndDay)
    Write-Host "'-Assembly Read Throughput Stats" "
    $stats += get-Stat - $strVM - Stat virtualDisk.read.average entity - start $today9am. AddDays ($intStartDay) - finish $today5pm. AddDays ($intEndDay)
    Write-Host "'-writing flow Stats of collation" "
    $stats += get-Stat - $strVM - Stat virtualDisk.write.average entity - start $today9am. AddDays ($intStartDay) - finish $today5pm. AddDays ($intEndDay)
    Write-Host $stats.length
    # include data and gather stats on average for the day.
    } $groups = $stats | Group-object - property {$_.} Entity, $_. MetricId, $_. Instance}
    $report = $groups | % {
    New-object PSObject-property @ {}
    Description = $_. Group [0]. Description
    Entity = $_. Group [0]. Entity
    EntityId = $_. Group [0]. EntityId
    Instance = $_. Group [0]. Instance
    MetricId = $_. Group [0]. MetricId
    Timestamp = $_. Group [0]. Timestamp.Date.AddHours ($_.) Group [0]. Timestamp.Hour)
    Unit = $_. Group [0]. Unit
    Value = [math]: Round (($_.)) Group | Measure-object-propriete value - average). On average, 2)
    }
    }
    #Exporting the report to a CSV file.
    $strCSVSuffix = (get-date) m:System.NET.SocketAddress.ToString ('yyyyMMddhhmm')
    $strCSVFile = $strCSVLocation + $strCSVName + $strCSVSuffix + "_", ".csv".
    $report | Export-Csv $strCSVfile - NoTypeInformation - UseCulture

    Thank you, Tony.

    (1) Yes, you can call Get-Stat with several characteristics, the downside is that the results will be mixed and you'll need to extract the correct metric/value objects. What's even better, you can also move all the virtual machines in a single call to Get-Stat.

    (2) the Export-Csv does not specify the order of the columns in the .csv file, I'm afraid.

    The alternative is to write or build the .csv file yourself.

    Capture each line as you like it in a string, and then write that string to a file.

    This is the update script

    # Main Variables $sVCentre = "VC IP" $sVCUser = "administrator@domain" $sVCPwd = "password" $strVMWildCard = "*" $strCSVName = "Stats-AvgVMDiskWriteStatsWorkingday" $strCSVLocation = "c:\"
    $metrics = "virtualDisk.totalWriteLatency.average","virtualDisk.totalReadLatency.average",
        "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average",
        "virtualDisk.read.average","virtualDisk.write.average" # define the start and finish times for a working day. $today9am = (Get-Date -Hour 9 -Minute 0 -Second 0)
    $today5pm = (Get-Date -Hour 17 -Minute 0 -Second 0)
    $intStartDay = -1$intEndDay = -1## Begin Script
    
    #Connect to VCConnect-VIServer $sVCentre -User $sVCUser -Password $sVCPwd -ea silentlycontinue$arrVMs = Get-VM | where-object {$_.Name -like $strVMWildCard}
    $stats = Get-Stat -Entity $arrVMs -Stat $metrics -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
    # group the data and collate the stats into averages for the day.$groups = $stats | Group-Object -Property {$_.Entity, $_.MetricId, $_.Instance}
    $report = $groups | % {
        New-Object PSObject -Property @{
            Description = $_.Group[0].Description
            Entity = $_.Group[0].Entity
            EntityId = $_.Group[0].EntityId
            Instance = $_.Group[0].Instance
            MetricId = $_.Group[0].MetricId
            Timestamp = $_.Group[0].Timestamp.Date.AddHours($_.Group[0].Timestamp.Hour)
            Unit = $_.Group[0].Unit
            Value = [math]::Round(($_.Group | Measure-Object -Property Value -Average).Average, 2)
        }
    }
    #Exporting the report to a CSV file.$strCSVSuffix = (get-date).toString('yyyyMMddhhmm')
    $strCSVFile = $strCSVLocation + $strCSVName + "_" + $strCSVSuffix + ".csv"$report | Export-Csv $strCSVfile -NoTypeInformation -UseCulture
    
  • E-mail from Apple in the preferences (El Capitan) settings is not accepting my password for my email provider, once again?

    E-mail from Apple in the preferences (El Capitan) settings is not accepting my password for my email provider, AGAIN?  This happens with google, aol, etc, etc, etc. The password is never wrong, that it's just something that happens with Apple OS from time to time. Why can't they solve this!  He emerges finally upward, but at the same time, relentless and software Apple alerts does not receive your mail via the mail app which is now linked to the mail, notes, reminders, calendar, etc.  Any thoughts on a fix?  Or should I just kill app Apple mail, once and for all?  So annoying! I now have another 45 minutes on this problem with no resolution!

    This message has ended up in Mountain Lion and is coded for Messages (filter just to see the messages on the Messages (the application))

    I asked to be moved for you.

    20:23 on Tuesday. March 1, 2016

     iMac 2.5 Ghz i5 2011 (Mavericks) 10.9
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro (Snow Leopard 10.6.8) 2 GB
     Mac OS X (10.6.8).
     a few iPhones and an iPad

  • Setting permissions for several files at once

    I'm sure this has been asked here, but I'm not (although I have seen that it is claimed for several years on various forums around the Internet with zero answers concrete)...

    I use to be able to grant everyone | full control on several files at once, but for some reason that is completely beyond me, 7 (and as I read it, it's from vista forward) does not display the Security tab so I have to grant permissions one by one.

    It goes without saying, but I will anyway, it's silly.  There is no 'improvement' if it is more difficult, so I have to say that I don't see anything beneficial as to why this was changed.

    Is that it will be restored to how it was before and if not, why?  I'm not a programmer, so I won't make all orders or I will visit the group permissions or whatever.

    I want to be able to select multiple files/folders at the same time and grant permissiong in 2 clicks of the mouse.

    Feasible?  Or this function a round permanantly filed because someone thinks they've created something better?

    Here are a few options:

    • If permissions should affect all the files in a folder: apply the permissions in the whole file.
    • If the permissions should affect only some files in a folder: temporarily move the files in a folder that is clean, then apply permissions to this folder. Now, move the files to return whence they came.
    • If the file names can be treated with a wildcard character, for example * .jpg: use cacls.exe to command prompt to set the permissions.
  • paymentservice_get_price for several items at once?

    Hello BBNDK Devs.

    To try to fill our application in stores before the user interface with price values of each element, we call paymentservice_get_price batch for the items displayed (by SKU). This however results in a superposition of loading temporary to add above the main window for each of these requests (which are done in sequence). Is there one recommended way to do to avoid this? Are there factors to design replacement? We could simply not display the price in the user interface and the user only sees the price in the purchase confirmation dialog, but this is less than desirable. We could also do more on the plan to fly in which we ask that the prices of the items visible, but translates the user experience being constantly interrupted by this superimposition of loading. All thoughts

    Thank you!

    Stéphane

    Hi Stephane,

    Currently, the overlay can be avoided. For BBOS he's had recently introduced a call to retrieve digital assets in an asynchronous way (without any recovery) allowing the goods to recover in the background. Once this feature made its way to the NDK, you should be able to do the same thing.

    See you soon,.

  • Need a powercli for bulk VM build

    I'm looking for powercli script who build virtual machines and with the configuration below.

    name, model, oscust, cluster, file, data, ip, mask, gw, dns1, dns2 store

    something similar to this link, but in my environment didn't cluster data store.

    PowerCLi simple script for batch - VMwaremine - Artur Krzywdzinski VM deployment. Nutanix

    My email is on my blog, at the top right

  • PowerCLI for VM hardening 5.5

    Can someone please confirm below can be used for VM hardening: - (I got it from a pole)

    "Thanks for the tip, I was working on PowerCLI script filled with disa stig, hardening guide and this gave me the missing piece." Here is a summary:

    "I created the following entry from DISA stig d:\vmware stig\stig_vm.txt file:
    insulation. BIOS. BBS. Disable, true
    insulation. Device.connectable.Disable, true
    insulation. Monitor.Control.Disable, true
    isolation.tools.diskShrink.disable, TRUE
    isolation.tools.diskWiper.disable, TRUE
    log.keepOld, 10
    log.rotateSize, 100000
    RemoteDisplay.maxConnections, 1
    tools.guestlib.enableHostInfo, FALSE
    tools.setInfo.sizeLimit, 1048576
    vmci0. Unrestricted, FALSE
    isolation.tools.hgfsServerSet.disable, TRUE
    insulation. Device.Edit.Disable, true
    isolation.tools.autoInstall.disable, TRUE
    insulation. Tools.Copy.Disable, true
    insulation. Tools.dnd.Disable, false
    isolation.tools.setGUIOptions.enable, FALSE
    insulation. Tools.Paste.Disable, true
    insulation. Tools.ghi.AutoLogon.Disable, true
    insulation. BIOS. BBS. Disable, true
    isolation.tools.getCreds.disable, TRUE
    insulation. Tools.GHI.launchMenu.change, true
    isolation.tools.memSchedFakeSampleStats.disable, TRUE
    isolation.Tools.ghi.protocolhandler.info.Disable, true
    isolation.ghi.host.shellAction.disable, TRUE
    isolation.tools.dispTopoRequest.disable, TRUE
    isolation.tools.trashFolderState.disable, TRUE
    insulation. Tools.ghi.trayicon.Disable, true
    insulation. Tools.Unity.Disable, true
    isolation.tools.unityInterlockOperation.disable, TRUE
    insulation. Tools.Unity.push.Update.Disable, true
    insulation. Tools.Unity.Taskbar.Disable, true
    isolation.tools.unityActive.disable, TRUE
    isolation.tools.unity.windowContents.disable, TRUE
    isolation.tools.vmxDnDVersionGet.disable, TRUE
    isolation.tools.guestDnDVersionSet.disable, TRUE
    isolation.tools.vixMessage.disable, TRUE
    tools.setinfo.sizeLimit, 1048576

    $stig_vm = 'D:\VMWARE STIG\stig_vm.txt' import-Csv-to-head Name, Value

    : APPLY TO ALL MY_VM1
    {foreach ($line in $stig_vm)
    New-AdvancedSetting - MY_VM1 of the entity name ($line. (Name): value ($line.value) - Force - confirm: $false | Select the entity, Name, Value
    }

    : APPLY TO ALL VM
    {foreach ($line in $stig_vm)
    Get - VM | New-AdvancedSetting - name ($line. (Name): value ($line.value) - Force - confirm: $false | Select the entity, Name, Value. Export-Csv $output
    }

    I tried to follow the xls published by vmware, but I don't get in for example,.

    # List the virtual machines and their current settings

    Get - VM | "Get-AdvancedSetting - name" isolation.tools.autoInstall.disable "|" Select the entity, Name, Value

    It gives me no o/p... What does that mean?

    Help, please

    Thank you

    I meant the VirtualMachineConfigSpec to explain what is happening behind the scenes of the cmdlet.

    You can check this with Onyx.

    When a specific parameter is not present, the default value will be used.

    This does not mean that the default value will be displayed when you list the advanced settings.

    So, the script should work.

  • Look for multiple clips at once

    Hey there,


    So, I would like to get this right. If I use the direct link from first to Speedgrade, there is no way to easily apply a glance to multiple clips other than the use of adjustment layers?
    I have pictures of different places all over my calendar, it would be a pain to create layers of adjustment for all the clips.
    Back when I was using apple color, I just select them and drag a look at the selection and the bam, done.
    Is it really not possible with Speedgrade?

    In short, no... you can not select multiple clips in Sg to the class at the same time or drop a glance on. There are ways to copy grades but they are all by the clip, with the exception of using adjustment layers. And Yes, the creation of adjustment on a bunch of clips spread layers is a royal pain. Feel free to fill a feature request of the possibility to select several clips... and discontiguous multiple clips... for the ranking in some sort of batch.

    /Feature bug report form requires Adobe...

    https://www.Adobe.com/cfusion/mmForm/index.cfm?name=wishform

    I would like no end if it appeared within the programs.

    Currently, the two ways to do what you want is as above dummergold... Place the head on the clip you want to change, rest the mouse over the clip you want to copy from and click on 'C', or use the keypad 1-9 for copy/paste a grade.

    The other takes a little more ' splaining. The default guess of origin before the current clip (with head of reading about it). Count however many clips to the left that you want to use for your settings (up to 9) and using the keypad, click this number. So... If it's just the previous clip, you would click on the 1 on the numeric keypad. ALL the current standings will be replaced by what is on the clip you selected by entering your number and once again 1-9 clips before your currently selected clip.

    To reverse the process and choose a quality according to the item currently selected, you hold ALT first and then click on the sign '+' keypad to reverse the "default"... and then any number from 1 to 9, you hit on the pad will capture the rank of this clip, 1-9 after the currently displayed item, and drop this clip to replace all the existing settings. In order to work immediately after this clip for the shade desired put the playback head on a clip, hit the number 1-9...

    Back to grabbing the clip settings to before the item that is currently displayed, it's... ALT and the minus sign ' - '. Here again, the settings from that much before clips the clip ongoing hit 1a9 seizes.

    Once you get used to it, you can move along at a decent pace. Like you, I prefer to be able to skip the long however.

    Neil

  • Using PowerCLI for virtual disk latencies

    Hi all

    I'm trying to get the disk reading and latencies on some virtual machines

    I'm quite a beginner on PowerCLi apart from some ships a writing utility

    I checked this thread

    http://communities.VMware.com/thread/304827

    But these counters do not work for me

    Can someone please help?

    [vSphere PowerCLI] D:\Program Files\VMware\Infrastructure\vSphere PowerCLI > $stats += Get-Stat - entity "USB-SSAPP" - Stat virtualDisk.totalWriteLatency.average
    Start $today1am. AddDays ($intStartDay) - finish $today4am. AddDays ($intEndDay)
    [vSphere PowerCLI] D:\Program Files\VMware\Infrastructure\vSphere PowerCLI > $stats

    Returns nothing,

    I created all the variables that I'm providing in the command.

    Kind regards

    P

    You might start by checking what statistical level, the period you specified is defined in vCenter.

    "Latency" needs to at least level 2 metrics.

    I guess that "USB-SSAPP" is the name of a host ESX (i)?

  • upgrade VM NIC drivers for a computer virtual once VMtools and HW version upgrade to version 7

    Hi people,
    I just wanted to know your opinion on the VM NIC driver update once the VMS migrate from ESX3.5 to ESXi4.1 and as I am course upgrade VMware Tools 4 to 7 HW version. Please let me know as
    as the current network adapter is E1000. Need to move the VM NIC as well?

    Thank you
    vmguys

    as the current network adapter is E1000. Need to move the VM NIC as well?

    Hello

    you don't have to

    1. upgrade Vmware tools
    2. upgrade from version HW - don't forget that with version 8 VM can run only on ESXi5
  • Need a list of MAC addresses for all VMs in vcenter

    How go on sending a query to vcenter, and he pulled out a text file that contains all the mac addresses for all of my VM and vm name. Any help will be welcome. Thank you

    Hello, RadarG-

    You can do this quickly with something like:

    Get-View -Viewtype VirtualMachine -Property Name, Config.Hardware.Device | `    Select name,        @{n="MAC(s)"; e={($_.Config.Hardware.Device | ?{($_ -is [VMware.Vim.VirtualEthernetCard])} | %{$_.MacAddress}) -join ","}} | `    Export-Csv c:\temp\VMMACsInfo.csv -UseCulture -NoTypeInformation
    

    "It was essentially my post vNugglets.com" find VM with PowerShell - Fast as NETWORK card MAC address!.  If you are wanting just a list ivnventory of MAC addresses of your virtual machines, will be good.  But, if you are looking for a virtual machine by MAC address, or are perhaps looking for duplicates, there are other easier ways.

    Recently, I did 3 three MAC address of related messages (see to The MAC address of label to vNugglets).  There are to find virtual machines by MAC address, find MAC address duplicated and configuration of the MAC addresses on the VMs.

    Enjoy.

Maybe you are looking for