PowerCLI script is running slowly

My script lists each VM that has a RDM mapped with the MONDAY of each ROW. Very simple. No flashes do not. It is intended to get a "quick list" when I try to find that VM has a specific ID of LUNS mapped to it. It takes about 20 minutes to run. We have about 320 VMs in this environment.

Any ideas on how to speed it up?

$vms = get - VM

Foreach ($vm to $vms)

{

If (Get - VM $vm |) Get-hard drive | Where {$_.} DiskType - eq "RawPhysical"})

{

.name ($vm)

$Disks = get - VM $vm | Get-hard drive | Where {$_.} DiskType - eq "RawPhysical"}

Foreach ($Disk in $Disks)

{

$Lun = get-SCSILun $Disk.SCSICanonicalName - VMHost (Get - VM $VM). VMHost

$Lun.RuntimeName.Substring ($Lun.RuntimeName.LastIndexof ("L") + 1).

}

}

}

Thank you!

The use of views rather than repeatedly, run Get - VM, see reference;

Notice-EEG - vSphere PowerCLI cmdlets reference

Additionally, make sure that you use the latest version of PowerShell since it makes a huge difference to accelerate.

See you soon,.

Jon

Tags: VMware

Similar Questions

  • I keep getting messages "Stop running this Script?" who advise they are originally my web browser run slowly. How do I rectify this?

    It is not a clear sign of the browser slows down. It does not seem to be limited to any Web site.

    Sometimes, this problem is caused by an add-on that begins interacting with the page after most loads content, so you don't notice the problem until you get the message. Can the extension Skype Click-to-Call cause this problem.

    In other cases, the problem may be caused by the content of the page.

    If you find any model of the script that runs slowly, say Firefox? Script names that start with chrome: / / or resource: / / address either parts of Firefox or an extension. Starting with http:// or https:// usually script names are part of the site you visit.

    For more information, you can try our technical support article: script is unresponsive warning - what it means and how to fix it.

    Another good cause script errors is unresponsive on Windows Vista and newer is the feature of mode of the Flash player plugin. This feature has the security benefits, but it seems to have serious compatibility problems on some systems. You can disable it using the page modules. Either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click on Plugins. On the right side, find 'Shockwave Flash' and click on the link for more. Then uncheck the box for "Enable Adobe Flash protected mode" and try it for a day to see if that helps you.

  • copyright in the powercli script symbol

    I need to print the copyright symbol when a powercli script is run.

    but,

    write-host "Copyright ©" does not print a circle with a 'c' in there

    It prints just a 'c '.

    no idea how to get this printed on the screen

    Strange, who also works for me also, what happens if you use the below:

    Write-Host "Copyright $([Char]0169)"
    
  • 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:
  • Running PowerCLI scripting against vCenter occupies space of database in vCenter?

    Hi all

    Someone can confirm, running or collecting data using PowerCLI against vCenter occupy or use vCenter database space?

    Some commands (generally the things which create, modify (including the power on/off/suspend/move/run, etc.). or remove) will create event entries will be stored in the database of vCenter. Others who may are Connect-VIServer can also register an event. The "Get" cmdlets will not create entered events

    You can identify those who have the VI Client open and see if the script causes all events appear in the lower pane or by running Get-VIEvent on the vCenter server after your script is run (search for events based on the username)

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

    Hi all

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

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

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

    Thank you

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

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

  • PowerCLI script does not run from the SRM command line

    Hello

    Even if I put the Unrestricted PowerShell execution policy, when I try to run a script from a command line step added in SRM, the script is run. The newspaper of SRM, I find:

    [#2] dynamicType = < unset >

    [#2] faultCause = (vmodl. NULL in MethodFault),

    [#2] result = {(dr.secondary.CalloutResult)

    [#2] dynamicType = < unset >

    [#2] commandLine = "c:\windows\system32\cmd.exe /c C:\Source_code_VMware\Scripts\redirect.bat C:\CACINTEL\Source_code_VMware\Scripts\DRSrules_TEST.ps1."

    out of [#2] = 'file C:\Source_code_VMware\Scripts\DRSrules_TEST.ps1 cannot be loaded.

    [#2] because the execution of scripts is disabled on this system. Please see "get - he.

    "[#2] lp about_signing" for more details.

    [#2] On line: 1 char: 2

    [#2] + & < < < < "C:\\Source_code_VMware\\Scripts\\DRSrules_TEST.ps1".

    [#2] + CategoryInfo: NotSpecified: (:)) [], PSSecurityException)

    [#2] + FullyQualifiedErrorId: RuntimeException

    [#2]

    [#2] ",

    [#2] returnValue = 1,

    [#2]    },

    [#2] msg = ","

    Once more, the execution policy is set to unrestricted:

    [vSphere PowerCLI] C:\Program Files (x 86) \VMware\Infrastructure\vSphere PowerCLI > Get-ExecutionPolicy-list

    Scope ExecutionPolicy
    -----                                               ---------------
    MachinePolicy Undefined
    UserPolicy Undefined
    Undefined process
    Undefined CurrentUser
    Unrestricted LocalMachine

    Of course, the command works fine if I run it manually from a command prompt.

    Any idea?

    Thank you in advance

    Make sure that add you in the 32-bit version of PowerShell, MRS. uses PowerShell to 32-bit host.

    It is the one that always gets me!

  • A script in this movie is causing Adobe Flash Player to run slowly

    Hello

    I have a recursive function that long runs more than 20 seconds. But within 15 seconds, I had a "a script in this movie is causing Adobe Flash Player to run slowly". Is it possible for me increase the default time.

    Kind regards

    Kelifaoui has.

    Click on file/publish/flash settings and set the script timeout.

  • I get a popup saying that a script is running

    I keep getting a pop up saying script runs and can cause your computer to slow down or become that unresponsive and click on Yes stop running script for her to let me use my pc. How can I stop this? It shows every 15 minutes.

    Hello

     
     
    1. have you made changes on the computer?
    2. what application receive you the error message?

    You can check the link provided and check:
    How to resolve script errors in Internet Explorer on Windows computers
    http://support.Microsoft.com/kb/308260


    Error message: "a script on this page slows down Internet Explorer runs slowly.
    http://support.Microsoft.com/kb/175500
  • Best way to encapsulate PowerCLI scripting

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

    .\Create-TestingBoxen.ps1

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

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

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

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

    Hello, alficles-

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

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

    ## start of script:  add PSSnapin if not already loadedif ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null ) {Add-PsSnapin VMware.VimAutomation.Core; $bSnapinAdded = $true}
    
    ## do all the good script stuff here##  stuff##  ...##  stuff
    
    ## at end of script, if given PSSnapin had to be loaded at start, unload it hereif ($bSnapinAdded) {Remove-PSSnapin VMware.VimAutomation.Core}
    

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

  • PowerCLI script to list the df - hl on all ESX hosts?

    Hi Expert,

    I have more than 100 esx host, and I need to list all the df - hl out for my report. Y at - it instead of connect on each esx host to get under output, powercli script that I can use to remove similar information?

    Size of filesystem used Avail use % mounted on

    / dev/sdaa2 20G 1.5 G 17G 8%.

    / dev/CCISS/c0d0p1 1.1 G 118 M 909 M 12% / Boot

    / dev/sdaa6 9.7 G 151 M 9.0 G 2% / Home

    / dev/sdaa7 9.7 G 151 M 9.0 G 2% / tmp

    / dev/sdaa5 9.7 G 317 M 8.9 G 4% / var

    / dev/sdaa8 494M 212 M 257M 46% /vmimages

    Please advice. Thank you

    Are you allowed to enable SSH on servers ESX (i)?

    And are you allowed to establish a SSH session on each ESX (i) Server?

    You have an account and a password on each ESX (i) server that can run the command 'df '?

    If it is Yes, then you can use something like plink.exe in consequence of PuTTY to connect to each ESX (i) server, run the command "df" and retrieve the output.

    There are several available examples to use plink.

    And don't forget that you will need a fingerprint for each server ESX (i) will be stored on the client from which you are running the script.

  • 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 '.

                  

  • 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.

  • PowerCli script prompts for user input

    Hello

    Below powercli script prompt for user input. Don't know how to fix it. I don't want it calls for the release of the user, as I am the code as part of the largest script runinng. How can I run in silent mode? Any help would be very happy.

    function VMHostDiskDetails {}

    $DateVar = get-date - uformat "% Y-%m-%d_%I.%M.%S.%p".

    $VMHosts = get-VMHost # get all the VM host

    $Datastores = $VMHosts | Get-Datastore # get the info from the data store for all VMHosts

    $VMHostStorage = $VMHosts | ForEach-Object {#Then, for each VMHosts, download the VMHostName

    $VMHost = $_. Name

    $_ | Get-VMHostStorage | Select-Object - expandProperty FileSystemVolumeInfo | `

    {ForEach-Object

    $VMHostStorageName = $_. Name

    Add-Member - InputObject $_ - MemberType NoteProperty-name FreeSpaceMB-value ($Datastores |) Where-Object {$_.} Name - eq $VMHostStorageName}). FreeSpaceMB - PassThru | `

    Add-Member - MemberType NoteProperty-Name HostName-value $VMHost - PassThru

    Add-Member - MemberType NoteProperty-name TimeStamp-value $DateVar

    }

    }

    $VMHostStorage | Select the host name, name, mode, Type, capacity, FreeSpaceMB, path, TimeStamp | Export-Csv VMHostStorage.csv - notype

    }

    VMHostDiskDetails

    Thank you

    M

    The 2nd line Add-Member does not have the object on the pipeline.

    The 3rd line Add-Member had a parameter - PassThru.

    function VMHostDiskDetails {
    
         $DateVar = get-date -uformat "%Y-%m-%d_%I.%M.%S.%p"
    
         $VMHosts = Get-VMHost mmmstv004* # Get all the VM-Hosts
         $Datastores = $VMHosts | Get-Datastore # Get the Datastore info for all the VMHosts
    
         $VMHostStorage = $VMHosts | ForEach-Object { #Then, for each VMHosts, get the VMHostName
              $VMHost = $_.Name
    
              $_ | Get-VMHostStorage | Select-Object -expandProperty FileSystemVolumeInfo | `
    
              ForEach-Object {
                   $VMHostStorageName = $_.Name
                   Add-Member -InputObject $_ -MemberType NoteProperty -Name FreeSpaceMB -Value ($Datastores | Where-Object {$_.Name -eq $VMHostStorageName}).FreeSpaceMB -PassThru | `
                   Add-Member -MemberType NoteProperty -Name HostName -Value $VMHost -PassThru | `
                   Add-Member -MemberType NoteProperty -Name TimeStamp -Value $DateVar -PassThru
    
              }
         }
    
         $VMHostStorage | Select HostName,Name,AccessMode,Type,Capacity,FreeSpaceMB, Path, TimeStamp | Export-Csv VMHostStorage.csv -notype
    }
    
    VMHostDiskDetails
    

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • 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

Maybe you are looking for

  • IOS 10.0.2 nightmare

    I've updated to 10.0.2 and on my 3 month old that I call 6 battery in front of me, of 100% this morning, that he ran to 28 percent in mid-afternoon after very little use. It is also makes me to distraction that I must now press the "home" button to g

  • Problem notification Center

    Hi all, it is a small problem I have. There is the photo of my notification Center. As you can see the 'today' tab have a brilliant Ray surround. Normally this should only appear when I press the Tab key. But if I chose the tab 'Today' or 'Notificati

  • Tecra S3 and the replacement DVD drive

    Hello Portable model is Tecra S3 PTS30A-03E008DVD disc model is UJ - 832DVD player reference number is G8CC0002Q120 The DVD drive no longer works and I'm looking to install a new one. Is the Toshiba Ultra Slim Bay DVD SuperMulti DrivePart number - PA

  • Laptop of HP ENVY m7: the toolbar of the touchpad does not work

    When I click on the toolbar of the touchscreen keyboard, the keyboard just does not appear. Also when I touch with my finger on the screen somewhere where I would like to write the search bar, for example, the keyoard touch does not show. The only wa

  • ENGISH speaking of download for windows 7

    I need to reinstall my windows 7 English, I go as far as to enter my product key, which he checks and then it asks me for the country. It does not have an English speaking country to download.  I contacted support and they sent me the same link I tri