Alert shadow in vSphere PowerCLI script

Hi all

I have been using the script from this site with great success.

http://vnucleus.com/2011/07/PowerCLI-script-to-alert-on-snapshots-in-vSphere/

What I'm trying to understand it how to change the script, then he will send a report, even if there are no snapshots on virtual machines?

Can you get it someone please let me know what I should do?

Thank you

Ray

Someis lost during the copy/paste, it seems.

I've corrected the above lines, please try again.

Tags: VMware

Similar Questions

  • need help with first vsphere powercli script

    Greetings,

    Asked me to write a script to iterate over all the virtual machines in a given folder and to stop.  The name of the folder is blue (and is deep in several files).

    So far, I have:

    $svr = Connect-VIServer-Server svr-protocol https-user--password...

    $fldr = get-file-server $svr - blue name

    I don't know what to do next.  I would like to somehow get a picture of the VMS in the Blue folder, and then run:

    {foreach ($vm to $vmlist)

    Get - VM $vm | Stop-VMGuest

    }

    How can I do this?  Ideally, it should be wrapped in a function that I could pass the name of the file, because I really need to stop the virtual machines in the blue folder and a few others, too.

    Any help would be greatly appreciated.

    Thank you

    -John

    You can specify the file on the location of the Get-VM cmdlet parameter.

    Something like that

    foreach( $vm in (Get-Vm -Location (Get-Folder Blue)) {
        $vm | Shutdown-VMGuest
    }
    

    In PowerShell and PowerCLI, there is of course more then a way to get there.

    It should work as well

    Get-Folder Blue | Get-VM | %{
       Shutdown-VMGuest -VM $_
    }
    

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • 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

  • PowerCLI script to display the number of vCPU by VMhost use

    Hi all

    I'm looking to get help here with powerCLI script to list each total number of ESXi vCPU host that is used to determine if there are any ESXi host CPU is more engaged.

    According to suggestion of performance in some blog vExpert, is around 1: 3 of Jepp core ratio: vCPU allocated, then how to display the report with the powerCLI for something like this:

    PRODESXi01
    Total of nuclei available: 32
    Used by the virtual machine: 28

    PRODESXi02
    Total of nuclei available: 32
    Used by the virtual machine: 38

    So according to the result above, the PRODESXi02 is more committed by 6vCPU allocated to the virtual machine.

    Note: The available total carrots is taken from the value of logical processors from the contents tab, when you click on the vSphere console.

    How to get this report using PowerCLI?

    Thank you

    You mean something like this?

    {Foreach ($esx in Get-VMHost)

    $vCPU = get-VM-location $esx | Measure-object-property NumCpu-sum | Select - ExpandProperty sum

    $esx | Select Name,@{N='pCPU'; E={$_. NumCpu}},

    @{N = 'vCPU'; E = {$vCPU}},

    @{N = "Ratio"; E = {[math]: Round ($vCPU / $_.)} (NumCpu, 1)}}

    }

  • Recovery of vSphere PowerCLI with alarms

    Hello

    Can you please help me write a PowerCLI script that would recover the vSphere alarms?

    I want the script to show only alarms last 24 hours only if not acknowledged or deleted.

    Example:

    Get-VIEvent - MaxSamples 10 | Select Fullformattedmessage # this command shows me the last 10 events

    Win01 from green to Red alarm # the script "MyAlarm" should show me this alarm

    win01 on esx1.company.pri in Lodz is turned off

    win01 on esx1.company.pri in Lodz stops

    Task: Stop virtual machine

    win01 on esx1.company.pri in Lodz is turned on

    Message on win01 on esx1.company.pri in Lodz: running VMware ESX in a virtua...

    starts win01 on the host esx1.company.pri in Lodz

    Task: Power on virtual machine

    Task: Initialize turn

    Alarm"monitor the health status"on changed from yellow to green data centers.

    Help, please.

    If the alarm was not recognized and authorized, it should still show.

    You can see these alarms with

    $dc = get - file - name of data centers

    $dc. ExtensionData.TriggeredAlarmState |

    Select @{N = 'Entity'; E = {Get-view-Id $_.} Entity | {{Select - ExpandProperty name}}.

    OverallStatus,

    @{N = "alarm"; E = {(Get-View-ID $_.)} Alarm). Info.Name}}

    -What are you looking for?

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

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

  • Using Windows Powershell ISE with vSphere PowerCLI

    Hey everybody,

    I'm completely newbieand have just started on the track "managing vSphere with powershell. First problem:

    Is it possible to use Windows Powershell ISE with vSphere cmdlets or can I only use the vSphere PowerCLI?

    I wish I could type my commands directly in the window of the ISE and manage my scripts etc because of this (I find myself n always cut and paste from Notepad when you use the PowerCLI).

    If so, how should I do this?

    I guess its something simple, but when I run the ISE seems not to have registered vSphere cmdlets. I guess I missed something?

    Thank you

    Marc

    In the ISE if you run the following cmdlet, you will get the registered PowerCLI cmdlets:

    Add-PSSnapin "Vmware.VimAutomation.Core".

  • Addition of VMDK to VM in new vSphere PowerCLI

    Hi all

    This message goes hand in hand with may last post and involve the transfer of uncomfortable the new vSphere PowerCLI from the VItoolkit on VMware 3.5.

    One of my scripts uses some functions to add existing VMDK files on an existing virtual machine. The big problem is - this code is a reason any invalid in the CLI of new power.

    As you can see - functions have simple command line with VM, VMDK file and the number of SCSI controller. Can someone hazard a guess then that this process is no longer valid for PowerCLI?

    Thank you in advance: o)

    1. Functions

    # #Examples

        1. Add HD "PC4" "vmfs2" "PC4/PC4.vmdk" "controller SCSI 0".

        2. VM-delete-HD 'name' "disk hard 3" $TRUE ".

    function add-HD {}

    Param ($VMname, $SCSIcntrl, $DSname, $Filename)

    #write - host "adding disc $Filename data $DSname $VMname-VM store."

    $vm = get - View (Get - VM $VMname) USER.USER

    $ds = get - View (Get-Datastore-name $DSname) USER.USER

    {foreach ($dev to $vm.config.hardware.device)}

    If ($dev.deviceInfo.label - eq $SCSIcntrl) {}

    $CntrlKey = $dev.key

    }

    }

    $Unitnumber = 0

    $DevKey = 0

    {foreach ($dev to $vm.config.hardware.device)}

    If ($dev.controllerKey - eq $CntrlKey) {}

    If ($dev. Unitnumber - gt $Unitnumber) {$Unitnumber = $dev. Unitnumber}

    If ($dev.key - gt $DevKey) {$DevKey = $dev.key}

    }

    }

    LogEntry $sLogFile 'DeviceKey is $DEVKEY, UnitNUm is $UnitNUmber, ContrlKey is $CntrlKey.

    $spec = new-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.deviceChange = @)

    $spec.deviceChange += new-Object VMware.Vim.VirtualDeviceConfigSpec

    $spec.deviceChange [0] = new-Object VMware.Vim.VirtualDisk .device

    $spec.deviceChange [0].device.backing = new-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

    $spec.deviceChange [0].device.backing.datastore = $ds. MoRef

    $spec.deviceChange [0].device.backing.fileName = "" + $Filename

    $spec.deviceChange [0].device.backing.diskMode = "independent_persistent".

    $spec.deviceChange [0].device.key = $DevKey + 1

      1. UnitNUmber SCSIID 7 is reserved for the controller - so ignore it and move on to 8.

    If ($Unitnumber - eq 6) {$Unitnumber = $Unitnumber + 1}

    $spec.deviceChange [0].device.unitnumber = $Unitnumber + 1

    $spec.deviceChange [0].device.controllerKey = $CntrlKey

    $spec.deviceChange [0] .operation = 'Add '.

    $vm. ReconfigVM_Task ($spec)

    }

    delete-HD {} feature

    Param ($VMname, $HDname, $Delflag)

    #write-host "' disassembly disk for VM $HDname: $VMname" "

    $vm = get - View (Get - VM $VMname) USER.USER

    foreach ($dev in $vm. Config.Hardware.Device) {}

    If ($dev. DeviceInfo.Label - eq $HDname) {}

    $key = $dev. Key

    $name = $dev. Backing.FileName

    }

    }

    $spec = new-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.deviceChange = @)

    $spec.deviceChange += new-Object VMware.Vim.VirtualDeviceConfigSpec

    $spec.deviceChange [0] = new-Object VMware.Vim.VirtualDevice .device

    $spec.deviceChange [0].device.key = $key

    $spec.deviceChange [0] .operation = 'delete '.

    $vm. ReconfigVM_Task ($spec)

    If {($Delflag)

    $svcRef = new-object VMware.Vim.ManagedObjectReference

    $svcRef.Type = 'ServiceInstance.

    $svcRef.Value = 'ServiceInstance.

    $serviceInstance = get-views $svcRef

    $fileMgr = get-view $serviceInstance.Content.fileManager

    $datacenter = (get-View (Get - VM $VMname |)) Get-Datacenter) USER.USER) .get_MoRef)

    $fileMgr.DeleteDatastoreFile_Task ($name, $datacenter)

    }

    }

    Below the new versions of my HD - Add and Remove-HD functions.

    The functions Add - HD had an error in this line

         $spec.deviceChange[0].device.backing.fileName =" " + $Filename
    

    The function Remove-HD can be optimized in vSPhere.

    With the help of the LayoutEx.Disk property, you can now find all the files that are located behind a virtual disk.

    The new versions are attached because there are some hooks in the code.

  • Collection for the PowerCLI scripting requirements

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

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

    Your suggestions of entry, welcome masters strategies.

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

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

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

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

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

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

    Take a look.

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

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

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

    But we needed equality PowerCLI ESX command below script

    # cat/proc/driver/cciss/cciss0

    cciss0: HP Smart Array P400i controller

    Board ID: 0x3235103c

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

    hpsa0: HP Smart Array P410i controller

    Board ID: 0x3245103c

    Firmware version: 5,70

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

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

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

    The sample output:

    
    Name                     Model                Controller Type   Controller Firmware                           hpsa Driver Version----                     -----                ---------------   -------------------                           -------------------esxihost1022.local    ProLiant DL380 G6    Smart Array P410i    HP Smart Array Controller HPSA1 Firmware 6.40    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1023.local    ProLiant DL380 G6    Smart Array P410i    HP Smart Array Controller HPSA1 Firmware 6.40    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1024.local    ProLiant DL380 G6    Smart Array P410i    HP Smart Array Controller HPSA1 Firmware 6.40    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1033.local    ProLiant DL360p Gen8    Smart Array P420i    HP Smart Array Controller HPSA1 Firmware 5.42    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1034.local    ProLiant DL360p Gen8    Smart Array P420i    HP Smart Array Controller HPSA1 Firmware 5.42    Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1041.local    ProLiant DL380 G5    Smart Array P400    HP Smart Array Controller HPSA1 Firmware 7.24    VMware scsi-hpsa 5.0.0-17vmw.500.0.0.469512 2011-08-19 01:58:59.000esxihost1042.local    ProLiant DL380 G5    Smart Array P400    HP Smart Array Controller HPSA1 Firmware 7.24    VMware scsi-hpsa 5.0.0-17vmw.500.0.0.469512 2011-08-19 01:58:59.000esxihost1160.local    ProLiant BL460c Gen8    Smart Array P220i    HP Smart Array Controller HPSA1 Firmware 5.22    Hewlett-Packard scsi-hpsa 5.0.0-40OEM.500.0.0.472560 2012-08-24 21:04:51.000esxihost1161.local    ProLiant BL460c Gen8    Smart Array P220i    HP Smart Array Controller HPSA1 Firmware 5.22    Hewlett-Packard scsi-hpsa 5.0.0-40OEM.500.0.0.472560 2012-08-24 21:04:51.000
    
  • PowerCLI script start vm and check the boot

    Hello

    I try to do a powercli script to start the virtual machine and check when the (windows) operating system is completely open and ready.

    How can I do?

    Maybe this helps...

    Start-VM - VM - runAsync

    $vm = get - vm

    Start-Sleep - seconds 20;

    $vm | Get-VMQuestion | Game-VMQuestion - version - confirm: $false;

    do

    {

    Start-Sleep - seconds 5;

    $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

    } While ($toolsStatus - not "toolsOK");

  • 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

  • Need a powercli script to create a new account a local administrator on all ESX and ESXi hosts in the vcenter

    Hi all

    If someone can help me with a powercli script to create a new account a local administrator on all ESX and ESXi hosts in the vcenter, create a role called admin and give all access except the root. This shoulb be past by a virtual centre.

    Very much appreciated to help him.

    Kind regards

    MelLvin

    I suspect that you posted your question to the wrong thread

    This requires only a minor change to the script above actually.

    Something like that

    $groupName = "group"$accountName = "user"$accountPswd = "password"$accountDescription = "A user"
    
    $esxlist = Get-VMHostforeach($esx in $esxlist){    Connect-VIServer -Server $esx -User root -Password "password"
    
        Try {      Get-VMHostAccount -Id $groupName -Group -ErrorAction Stop | Out-Null    }    Catch {      New-VMHostAccount -Id $groupName -GroupAccount | Out-Null    }
    
        $rootFolder = Get-Folder -Name ha-folder-root    Try{        $account = Get-VMHostAccount -Id $accountName -ErrorAction Stop |        Set-VMHostAccount -Password $accountPswd -Description $accountDescription -AssignGroups $groupName    }    Catch{        $account = New-VMHostAccount -Id $accountName -Password $accountPswd -Description $accountDescription -UserAccount -GrantShellAccess -AssignGroups $groupName    }
    
        $rootFolder = Get-Folder -Name ha-folder-root    New-VIPermission -Entity $rootFolder -Principal $account -Role admin
    
        Disconnect-VIServer -Confirm:$false}
    
  • PowerCLI script to migrate virtual machines to the new vCenter environment

    Hello world

    in the next few weeks, we need about migrate 700 VMs (Windows/Linux) server to a new environment (new vCenter, new hosts, but VMs will remain on same data warehouses). VMs will be migrated not in one batch, but rather from time to time (which, however, can understand the need to migrate some 10s of virtual machines at the same time).

    Cluster names and folder structure will be identical to the old and the new vCenters. As host in the new vCenter names differ from those in the old vCenter, thought to provide a table of 'translation', which tells the script to save a given VM on host B (new vCenter) when having been registered in order to host a (old vCenter) and so on.

    I thought writing a PowerCLI script which, broadly speaking, can accomplish the following steps:

    • Connect to vCenterOld and vCenterNew
    • Correspondence table of host to read from a file (see step "register VM vCenterNew below)

    Then, in a loop:

    • Ask VM name
    • Get the settings of the virtual machine: Datastore/path, network/Portgroup, HA restart priority, host, folder, note
    • View the parameters and the VM name and request confirmation migrate the virtual machine
    • Turn off VM (closed OS gracefully, but force power off if power status is still not equal 'off' after a time given)
    • To unsubscribe from VM vCenterOld (removal of inventory)
    • Registry of the VM to the data store vCenterNew (assumptions: same folder as vCenterOld, host names are different, but for each source in vCenterOld host a host of destination in vCenterNew for you join the virtual machine to can be provided, that is, CSV)
    • The value of VM portgroup (same name as in vCenterOld)
    • Set VM HA restart priority
    • PowerON VM
    • Wait / check the VM (for example, ping) connectivity / continue immediately if the virtual machine is accessible or after a certain time if the virtual machine is still inaccessible
    • Confirm that the virtual machine has been migrated successfully, OR ask the user to check the connectivity of the virtual machine

    Now to my questions:

    • Is anyone know about an existing script that does something similar or contains parts that can be useful to compile a script like this?
    • How can vCenter two connections at the same time been managed within a PowerCLI script - or doesn't work at all and a connect/disconnect to/from the two vCenters must be completed for each virtual computer?

    Many thanks for any help.

    The following seems to work for me

    $vm = Get-VM -Name MyVM$nic = Get-NetworkAdapter -VM $vm $vdPG = $nic | select -ExpandProperty NetworkName
    
    Get-VDPortgroup -Name $vdPG
    

Maybe you are looking for