This is the 4th post of a series of 6 articles entitled WMI Week“. It tends to covers the automation tasks around WMI mainly using the powershell WMI module.

The first gives a short introduction concerning WMI, and show what tools are usefull when working with WMI. The second post covers how to manage WMI namespaces using windows powershell. The third post highlights how we can, create, retrieve delete, and manage WMI classes.  The fourth post  (this one) covers everything you need to know about WMI properties. The fifth post  will highlight everything related to WMI qualifiers, and the last and six’th post will explain everything you need the know about WMI Instances.

[important]By the way,the powershell WMI module is available here ( and Don’t forget to rate it  by clicking on the stars ;)).[/important]

Woop woopy!


powershell wmi week

 

Today I initially needed to leave for Amsterdam. But, there is a strike at AirFrace which made my journey to Amstrdam a bit more complicated. Luckly I managed to find another ticket and will be In Amsterdam about Sunday night. Right in time for the European PowerShell Summit !
I will meet all of my european powershell friends ‘physically’ for the first time. I spend a lot of time following their tweets, chatting through facebook of  Gtalk. Now we finally have the opportunity to meet. I am really looking forward to it 🙂

But in the mean time, I continue to work here In Basel / Switzerland. Currently, we work in implementing EMS with configmgr and intune integration at a big client from the region. It is really cool how microsoft has managed to make the mobile devices managable through SCCM. I can still see some main missing features such as bulk enrollement, but, the current state of the product is really interesting, and offers already a lot for our customers. Today I also start to integrate our first Windows 8.1 phone using the Workplace join. If I can find some powershell tasks related to it, I will most likley blog about it.

ems

Ready for integrating Windows phone 8.1 in configmgr using EMS

Let’s continue our WMI week and talk about WMI propperties with powershell.In today’s post, we will tackle the following topics:

  • What is a WMI property?
  • How do create / add a new WMI property?
  • How do retrieve information from a custom WMI property?
  • How do we delete wmi property?

What is  a WMI Property?

A WMI property is someting comparable to a variable, where the system puts information related to a specific topic in it. A specefic WMI class will then

Lets make this a bit more clear with an example:

To get a list of properties with Powershell version 2.0 we will use the following command:

The command will retrieve all the shares currently present on your local machine. If we ‘isolate’ one share, we will have the following results that is composed of properties (in red) and their respective values (in green).

 

Properties and values

 

Now these results returned by our previous command are properties as you can see, yes. But it is not 100% true (let’s say only at 98%). What is important to understand here is that the results that are returned here are actually all the instances contained in the WMI class win32_share.

[notice]Originally, what Get-WMIobject returns are not really “THE” properties, but an instance of these properties, which means a property AND a corresponding value. [/notice]

So the property always comes with a value once it as been instanciated. Technically, we could have classes that would not contain a value for a property. They would be waiting to be initiated and this new instance of that property would then receive a new value. Also, some properties could have a default value for example, which would be affected automatically to the instance once they are instanciated. A good example for this one would be a blanc value or “”.

How to use powershell to create WMI Properties ?

So now that we got that part clear (did we really? 0_O) let’s try to combine this with what we have done previously. If you recall, we created a Custom WMI NameSpace Called “District” and a custom WMI class named “PowerShellDistrict

Now that we have created these two elements, we will complete our custom class by adding to it a few properties; I was thinking of adding the following properties:

  • Author
  • Url
  • Topic
  • CreationDate

What do you think about it?…

I knew you would agree!

So I have added these values in to an array called “$arr” and created the custom WMI properties using the following logic:

add custom wmi properties

 

So we can see that the different properties have been sucessfully added to our WMI custom Class.

[notice] Remember, these properties will still need to be instanciated in a later step![/notice]

How to use powershell to find wmi property?

Now that we have created our specefic list of properties, it might be interesting to retrieve them. This is done by using the Get-WMIProperty cmdlet.

get custom wmi properties

This will list all the WMI properties that are currently in the Class.

You want to retrieve only one property ? Easy, you can use the -Propertyname parameter. To retriewe the Author property, we will use the following command.

 

And the following results would be returned:

Get wmi property author

How to use powershell to edit WMI properties?

Ok, now we got that one done. But as you can see, the value part is empty. That is because we didn’t specify a value for it. That would be ok, since the property would receive a value only when the class will be instanciated in the futur.

So how can we set a property value there now? And why would we actually want to do it? This can be usefull for properties that we know would not change, or at least, where we could offer a default value. Like the Url of my blog for instance, it will never change (at least it is not planned to in the futur). So that is a property where we could set a default value. In order to achieve that, we will have to use Set-WMIPropertyvalue

We use the following command in order to set web link to the url of my blog in the url wmi property:

As demonstrated below, the value would than be set

Set a new WMI property value

 

Actually, we don’t necessarly need to follow this order in order to set a value to WMI property. We could actually use the -PropertyValue parameter when we initialy created the property. We can demonstrate that by adding a new WMI custom property, let’s WorkplaceLocation.

For that we will use the following command:

And we will have the following results:

WMI workplace location

 

If we check our properties now, we can see the following listing by using Get-WMIproperty

 

Get-WMIProperty PowerShellDistrict

How to use powershell to remove WMI property?

So the last topic to cover is “How do we delete a WMI propery?

Very easy, simply by using the Remove-WMIProperty cmdlet from the  WMI-Commands Powershell module.

Actually, we added the WorkplaceLocation property, but this was only to use as an example on how to add a value to a WMI property while creating a new one. Let’s delete it using the following powershell command:
Remove WMI property

[important] All the “Remove-* cmdlets come with a built-in security mechanism, asking for confirmation prior to deleting it. This behaviour can be bypassed by using the “-Force” parameter[/important]

Need more details ? Check this youtube video on how to work with PowerShell and WMI properties”:

I also created two videos, one that shows how we actually create a NEW WMI property, a second one that show how we can delete it using PowerShell. Enjoy ! 🙂

How to add a WMI property using PowerShell:

 

How to remove a WMI property using PowerShell:

References:

WMI system properties:

http://msdn.microsoft.com/en-us/library/aa394584(v=vs.85).aspx

 

Voila, that was it for today, join me tomorow for the 5th day of our WMI week and we will tackle WMI qualifiers.

Bonne soirée 🙂

 

Stéphane[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]