PowerCLI script alarms
Hello.
I am trying to create a script that can take all the vm that triggered a specific alarm as "the processor of the virtual machine using" with an alert and put the machine names to a csv file. so far, I found a lot of information how to do that on all the alarms but not how I define one type of alarm. Is there a simple solution to this?
BR jorber
-Very well, so basically you want to filter anything that contains 'use of the virtual machine CPU' in AlarmInfo attribute.
The simple way to do this is to add a Where clause clause before heading to Export-CSV, as follows (see the changes in bold):
$ignoreAlarms = @("Virtual machine cpu usage") $vm_all = Get-View -ViewType VirtualMachine $Report=@() foreach ($vm in $vm_all){ foreach($triggered in $vm.TriggeredAlarmState){ If ($triggered.OverallStatus -like "red" ){ $lineitem={} | Select Name, AlarmInfo $alarmDef = Get-View -Id $triggered.Alarm $lineitem.Name = $vm.Name $lineitem.AlarmInfo = $alarmDef.Info.Name $Report+=$lineitem } } } $Report |Sort Name | Where {$ignoreAlarms -notcontains $_.AlarmInfo } | export-csv "c:\temp\VM-Red-Alarms.csv" -notypeinformation -useculture Invoke-item "c:\temp\VM-Red-Alarms.csv"
I also added a table of alarms to ignore, this way if you have several types of alarms that you want to ignore, you can add it to the table.
Change to 'Get-View - ViewType VirtualMachine' should give you a bit of a speed improvement as well
Tags: VMware
Similar Questions
-
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?
-
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 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: 28PRODESXi02
Total of nuclei available: 32
Used by the virtual machine: 38So 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)}}
}
-
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 & 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
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
-
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
-
Change the PowerCLI Script to use the DRS and DRS storage
Hello
I have a PowerCLI script that specifies a host and a data store to create a new virtual machine, which has served us well. Now we have activated the DRS and DRS storage and I wonder what to change in order to take advantage of these features. Are there commands to specify a cluster and the cluster data store and let the DRS to decide the initial investment for a new virtual machine? At the moment we put all hosts and the warehouses of data as variables and use them in the line below.
Thank you.
$newVM = New-VM-name $NewVMname - VM $TemplateName Datastore - $datastore - VMHost $vHost - confirm: $false - location $myName
You set a Datastorecluster?
If Yes, then you can replace the value of parameter data with the datastorecluster object store.
Replacing a VMHost with a cluster is not taken in charge I'm afraid.
But you can use something like this
New-VM-name TestVM Datastore - DSC - ResourcePool (Get-Cluster-name mycluster |) Get - Resourcepool - name of resources)
This will automatically select the VMHost.
The virtual machine appears in the root of the cluster.
DSC is the name of a datastorecluster in the cluster mycluster
-
PowerCLI Script Create Role in vCenter
I'm looking for is a PowerCLI script to create a role in vCenter. I found this post, and I wonder if it can be adapted to my needs. What I need specifically is a script to create a role with all of the following privileges:
System.Anonymous
System.View
System.Read
Global.SetCustomField
Datastore.AllocateSpace
Network.Assign
VirtualMachine.Inventory.Create
VirtualMachine.Interact.PowerOn
VirtualMachine.Interact.DeviceConnection
VirtualMachine.Interact.SetCDMedia
VirtualMachine.Interact.GuestControl
VirtualMachine.Config.AddNewDisk
VirtualMachine.Config.CPUCount
VirtualMachine.Config.Memory
VirtualMachine.Config.AddRemoveDevice
VirtualMachine.Config.Resource
VirtualMachine.Config.DiskExtend
Resource.AssignVMToPool
VApp.Import
StoragePod.Config
It is possible with a PowerCLI script?You can get the file to root like this
Get-file-name of data centers
The rest of your script seems ok.
-
I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly.
I tried to use for the function FolderByPath below, but don't know how to use it and have worked. Please help me in this.
Function Get-FolderByPath {}
< #.
. Records of recovery SYNOPSIS by giving a path
. DESCRIPTION the function will retrieve a record by its
path. The path can contain any type of leave (folder or)
Data Center).
. Author NOTES: Luc relaxing
. Path PARAMETER
The path to the folder.
This is a required parameter.
. Path PARAMETER
The path to the folder.
This is a required parameter.
. PARAMETER separator
The character used to separate the leaves in the
path. The default value is ' / '.
. EXAMPLE OF
PS > Get-FolderByPath-path ' Datacenter/Folder1/Folder2 ".
. EXAMPLE OF
PS > Get-FolderByPath-path "Folder1 > Folder2"-separator ' > '
# >
(param
[CmdletBinding()]
[parameter (Mandatory = $true)]
[System.String []] ${Path}.
[tank] ${delimiter} = ' / '.
)
{in process
If (((Get-PowerCLIConfiguration).)) DefaultVIServerMode - eq "Multiple") {}
$vcs = $defaultVIServers
}
else {}
$vcs = $defaultVIServers [0]
}
{foreach ($vc to $vcs)
{foreach ($strPath in $Path)
$root = get-file-name of the server data $vc centers
$strPath.Split ($Separator) | %{
$root = get-inventory-name $_-location $root - server $vc - NoRecursion
If ((Get-stocks-localisation $root-NoRecursion |)) Select--ExpandProperty name)-contains "vm") {}
$root = get-inventory-name "vm" - location $root - server $vc - NoRecursion
}
}
$root | where {$_-is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|% {}}
Get-file-name $_. Name - location $root. Parent - Server $vc
}
}
}
}
}
You can try to retrieve the object file by steps as well.
Something like this for example
$folder = get-data center-name 'LTX01-G8 | Get-file-name "LTX-servers | Get-file-name "LTX servers 0000 - 0299. Get-file-name Linux
I guess the first qualification in your path was the data center.
-
Add/update a powercli script - independent host license key
Does anyone know how to add/update a license key with powercli script.
I can do OK with LicenseAssignmentManager when connected to vcenter server, but I can't do when assigning a free license key to a stand-alone host as the ServiceInstance.Content.LicenseManager.LicenseAssignmentManager is $null. (esx5-623860)
See you soon,.
Matt.
Try something like this
$licMgr = get-view-Id "LicenseManager-ha-license-manager.
$licMgr.UpdateLicense ("00000-00000-00000-00000-00000", $null)
It will assign a trial license.
If you have a valid license key, replace the document "00000-00000-00000-00000-00000" with your key.
-
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
Some
is lost during the copy/paste, it seems. I've corrected the above lines, please try again.
Maybe you are looking for
-
Satellite P10 792, SD driver on w2k installation problems
I just installed windows 2000 on my P10 792. I downloaded the driver for the SD card in support page for w2k and I can't install it. He refuses to be installed in any case. If I have the strength to install manually, then I reboot I get a blue screen
-
Satellite Pro A60: Windows XP cannot start isapnp.sys driver missing or corrupt
I had a Satellite Pro A60 for about 3 years without problems. Last week Toshiba touchscreen developed vertical lines of the bleeding and I got error message "Windows XP cannot start because of the missing or damaged driver isapnp.sys. I tried using t
-
I can not send messages, I received
I can't send messages... I get... What do I do
-
No popup of parental controls (can't do anything this parental control need permission)
I had on my computer one day and there was no photo in the round back of the start screen so I tried to reinstall windows vista, but the screen has become weak as need my permission, but then he returned to normal and has nothing I restarted and tyie
-
One-stop shop of tile in Vista
Please tell me there is something so practical as XP tile horizontal/vertical window that fits in a single window on the desktop (with preserved borders, as opposed to the "optimize" option). Note: using the mouse to drag the edges should not be cons