VMware Cloud Community
RedTwirls
Contributor
Contributor
Jump to solution

Exporting all Objects with PowerCli

Hello,

I'm not into VSphere or vmware but a SCOM Administrator and i'm currently working on a solution to monitor our VCenter Server with SCOM. To be able to autoresolve alerts i'd need to find a way to export a list with all Objects from the VCenter Server to create them as instances in SCOM and map the Status of Error Events directly to these Objects.

I think this should be possible with PowerCli so the plan was to have a script export this list frequently and run a discovery Script from the SCOM Agent to automatically create the related instances. Does anybody know how this export could be done with PowerCli ? Since i'm not into vmware / vsphere and we dont have a test environment but only the Production System in our office i'm somewhat limited in just trying through the several commandlets to find this out.

Any pointer in the right direction of which commandlets may achieve this is as welcome as any script ideas that might help me out here.

Thanks and regards

Marco

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, I see.

When you want to display a map, it is indeed better to load the required objects in advance and refresh them regularly.

Did you already think about what you want to see in the map ?

A sample hierarchy could be

vCenter(s)                                     <- in $defaultVIServer after a Connect-VICenter
  datacenter(s)                              <- Get-Datacenter -Server <vc-name>
   cluster(s)                                   <- Get-Cluster -Server <vc-name>
      resource pool(s)                     <- Get-Resourcepool -Location (Get-Cluster <clustername>)
         guest(s)                               <- Get-VM -Location (Get-Resourcepool <resourcepoolname>)
      vmhost(s)                               <- Get-VmHost -Location (Get-Cluster <clustername>
         datastores                           <- Get-Datastore -Location (Get-VMHost <hostname>)
         network
            vswitches                         <- Get-VirtualSwitch -VMHost (Get-VMHost <hostname>)
                portgroup(s)                 <- Get-VirtualPortgroup -VMHost (Get-VMHost <hostname>)
   standalone host(s)
      guest(s)
      datastores
      network
         vswitches
             portgroup(s)

I added some of the cmdlets you can use to get the objects for a specific branch in the hierarchy.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Did you try the Get-Inventory cmdlet ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RedTwirls
Contributor
Contributor
Jump to solution

Yes, i tried the get-inventory cmdlet but it seems to return only the list of installed Virtual Machines while i also need the list of Resources which are being used.

For example, one message i have seen so far from vcenter is "'Datastore usage on disk' on LUN 1 changed from Gray to Green". When i use the get-inventory cmdlet this 'Object' LUN 1' is not listed, so i think i also need to export the list of Disk Objects somehow as well as NICs or other Objects that may be alerted on.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In the alarms you receive in SCOM you have all the information to retrieve the object from vSphere.

In this case you could launch a Get-Datastore cmdlet to get the PowerCLI object.

Why can't you do it this way ?

Why would you need to load all objects in advance ?

It is possible, but you will need to know which PowerCLI objects you need to load.

VirtualMachine, HostSystem, Datasttore, VirtualSwitch....

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

RedTwirls
Contributor
Contributor
Jump to solution

The thing is that i need to create those Objects in SCOM in advance because i cant map the Object State to the monitor otherwise. If i receive up and down events for different Objects and they are not correctly mapped an up event for Storage A resolves an Alert for Storage B. Another possible solution would be to just use a pickup rule which creates an Alert on every down Event but keeping the current State with a monitor is a far better to easen the work of our console operators, as well as the amount of tickets generated by them for the Server Team. Otherwise they might end up with x Alerts which are already outdated when they come in the office monday mornings and create unnecessary tickets for them. If i link the events correctly to the single Objects they will only get the Alerts for the Objects which are currently in faulty state everything else gets resolved automatically when it returns to green state.

Further i assumed that these Objects in vsphere may also change (new added, renamed etc.) therefore i wanted to do a frequent script discovery which automatically pushes the objects into the SCOM DB, so the class is already populated when related events pop up.

The Get-Datastore got me already a step further, thanks for the hint. Besides the Storage i'm currently looking for the Host Objects, i think that currently covers most of the events the vmware colleague writes out. Strange that he refuses to use or even try PowerCli at all, seems like a pretty powerful tool to me.

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Marco,

interesting stuff you're working on!

You can get the host objects with the Get-VMHost cmdlet.

It is a pitty that your VMware colleagues are not into PowerCLI yet. Maybe if they go to VMworld, they can visit Luc's PowerCLI presentation and become enthusiast.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

Ok, I see.

When you want to display a map, it is indeed better to load the required objects in advance and refresh them regularly.

Did you already think about what you want to see in the map ?

A sample hierarchy could be

vCenter(s)                                     <- in $defaultVIServer after a Connect-VICenter
  datacenter(s)                              <- Get-Datacenter -Server <vc-name>
   cluster(s)                                   <- Get-Cluster -Server <vc-name>
      resource pool(s)                     <- Get-Resourcepool -Location (Get-Cluster <clustername>)
         guest(s)                               <- Get-VM -Location (Get-Resourcepool <resourcepoolname>)
      vmhost(s)                               <- Get-VmHost -Location (Get-Cluster <clustername>
         datastores                           <- Get-Datastore -Location (Get-VMHost <hostname>)
         network
            vswitches                         <- Get-VirtualSwitch -VMHost (Get-VMHost <hostname>)
                portgroup(s)                 <- Get-VirtualPortgroup -VMHost (Get-VMHost <hostname>)
   standalone host(s)
      guest(s)
      datastores
      network
         vswitches
             portgroup(s)

I added some of the cmdlets you can use to get the objects for a specific branch in the hierarchy.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RedTwirls
Contributor
Contributor
Jump to solution

Thank you for the hierarchy and the related cmdlets! That will get me all i need from PowerCli Smiley Happy

For the map hierarchy: From SCOM Perspective im just about to create every Object i need as direct child of the Host Server to enable the mapping between Event and Object for automatic Alert Resolution. So i'm not creating a hierachry map but only a bunch of child objects for the Host System where the SCOM Agent is running.

A 'classical' map with an Object Hierarchy would be a distributed Application. It makes perfectly sense to implement something like this if the System Owners accept monitoring of their systems as something useful as it also enables generation of some nice Reports (Availability etc) but if everything they see in monitoring is 'We are being controlled now, we dont want that but we have been forced into it by our management' i will save that time for other stuff on my list.

Yes indeed, its an interesting topic to bring SCOM and vcenter together and i think there could be a lot of cool things done from monitoring side to check the health of the vcenter system and the virtual machines besides triggering on some Events in the Windows Log. As far as i have seen there also seem to be some cmdlets to fetch the status of different stuff directly which could nicely be used for a script monitor to measure the system state but since i depend on my colleagues in this case they will get what they ask for. A stable but quick solution to pick up the few events we could squeeze out of them.

Thanks a lot for the help on this topic, I really appreciate it!

Reply
0 Kudos