WMI introduction presentation for the PowerShell Bengalore UserGroup (PSBUG)

 

PSBUG + powershellDistrict I just finished my presentation for the PowerShell Bengalore UserGroup (PSBUG). It was really a great session where almost 30 people attended it!

Special thanks to dexter for having me  there and to have given me the opportunity to do this presentation.

The idea was to give an introduction to WMI / CIM technologies. Just enough to get you started if you are completely new to it, but still give some infos on the architecture of  CIM/WMI if you are not 100% new to it.

 

The presentation has been recorded and is available here –> https://plus.google.com/events/cb5m2g7c2ssj8pp5nep672quufs

 

Also, I took the opportunity to officially announce that I have create the following User Groups (Yep, you read plural tense there…)

  • Basel PowerShell User Group (BPUG)
  • Strasbourg PowerShell User Group (SPUG)

If you have any interests, questions, etc… or are from one of those city just get in touch with me (I don’t bite ^^)

More information concerning these two user groups will come soon.

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

How to manage WMI instances using powershell[WMI Week – Day 6]

This is the 6th 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  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 (this one) 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]

Ok, let’s Roll!


Howdy everybody!

Today it is sunday, and the sun is not really shining in lovely Strasbourg/France. So what to do when you are finished with all of your  sunday morning duties? Blogging? that seems to be a good idea.

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

  • What is an Instance ?
  • How do we retrieve instances ?
  • How to create / add a new instance?
  • How to delete / remove a instance?

 

What is an instance?

Let’s start from the beggining, and let’s answer this very first question that perhaps not everybody understand fully: What is an Instance ?

The wikipedia definition is the following one:

In class-based programming, objects are created from classes by subroutines called constructors. An object is an instance of a class, and may be called a class instance or class object; instantiation is then also known as construction. Not all classes can be instantiated –abstract classes cannot be instantiated, while classes that can be instantiated are called concrete classes. In prototype-based programming, instantiation is instead done by copying a prototype.

In other words, an instance is actually a copy of the specefic class in memory that has been given specefic data information.

What is that suppose to mean  ?

Exactly, I was going to ask the same question! Let’s make an example and make thinks more concrete.

Remember our Win32_Share class ? Well this is a class, that as is, has properties, and methods. As I discussed during the day 5:  the qualifiers, each time we create a share we have to provide obligatory data information (and this is also true while using a GUI). We will need to give the share a name, make it point to a specefic local path, maybe set a description and validate. That defined structure that will force us to give always the same data would be called the constructor. This info is then used to create an instance of the Win32_share class, which will be our new share, with the different properties such as: path, name, description etc…

 

How do we retrieve WMI instances ?

This is a question that will be easy to answer : All the cmdlets (or most of them) and even the GUI’s actually show you instances. When you browse to your shares section in the computer management mmc, you will see all the Instances that are currently present. In other words all the instances of Win32_share that currently exist on the local machine.

The MOW wmi explorer I presented you earlier this week during “day 1: Introduction” allow’s you to retrieve the instances very easily.

get instances

As you can see, there is a button in the center of the screen in order to retrieve the current instances of the win32_share class. We have then list of the 11 instances currently present on my computer. Those 11 instances are actually my 11 shares that are present on my machine (you can see ADMIN$, C$, E$ etc…)

With PowerShell it is extremly simple, and we have several ways to get them:

With the old and well knowed Get-wmiobject like this:

This will return all the current instances (shares) as showed here under:

Get-wmiobject

The second method is using the CIM cmdlets like with the Get-CimInstance :

Which will return us the exact same information:

get-ciminstance

And the third and last method is using the Get-WMIClassInstance:

returns exactly the same content.

 

get-wmiclassinstance

[notice]I have actually written the Get-WMIClassInstance only to keep a certain logic in the cmdlets available in the WMI module. It was really necessary for me to write it, but it made sense for me to keep a consistency in the cmdlets available in this module.[/notice]

How do we create WMI instances ?

there are several ways that exist in order to create instances. Until the WMI module there was no direct cmdlet that could actually create an instance. We had to go through a manual process.

If you want to create a new instance of the share class, this is how you would process using powershell only.

When we take a look in the $myNewInstance variable, we can see that the all the properties are listed, but their value is for each of them empty.

 

We will not need to provide all of the information, only the key qualifiers. How do we get them again ? exactly! using Get-WMIKeyQualifier as explained in yesterday’s post.

KeyQualifier

The URL property here is the KEY qualifier.  This means that we will not be able to create an instance of this class before that particular property has a value.

Let’s what there is in our previously created instance:

emptyproperties

All of the properties are empty except for the Description one where we had set a default value while working on the properties section during day 2

We can add values to the different properties by using $nameofthevariable dot the name of property (see example below).

SetValues

We can now create the instance using the Set-WMIClassInstance cmdlet as followed:

 

 

Instance created

If we go check in the MOW WMI explorer for instance in the District class

MOW Instance

 

References:

cim link –> http://technet.microsoft.com/en-us/library/jj553783.aspx

cheat sheet http://blogs.msdn.com/b/powershell/archive/2012/10/28/wmi-cheat-sheet-for-ps-users.aspx

 

Ok, that’s all for today folks. I see you guy’s tomorow where we will talk about mof files. 🙂

Cheers!

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

How to manage WMI qualifiers with PowerShell [WMI week – day 5]

This is the 5th 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  covers everything you need to know about WMI properties. The fifth post (this one)   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]

Ok,on y va!


Hello hello everybody. Today is was quite a day. I was originally suppose to leave for the amazing city of Amsterdam today in order to meet the other scripting geeks for the european Powershell summit. I am quite excited about the event, but I wont open my laptop before this sunday since the there is currently a strike in France (again…). I had to change my flight, and instead of flying out tonight, I will only on sunday night… 🙁 (I was planning to visit family and friends during this weekend..).I was really looking forward to run again on the never-ending-dikes from Almere like I did years ago (Time flies…).

anyway’s let’s continue our WMI week and talk about WMI qualifiers.In today’s post, we will tackle the following topics:

  • What is a WMI qualifier?
  • How to retrieve the qualifiers ?
  • What is a key qualifier and how to identify it.
  • How to create / add a new qualifier to a property?
  • How to delete / remove a qualifier?
  • Download link (Also available above)

What is a WMI qualifier?

a WMI what? WMI can already be confusing, but let’s add an extra layer, just for the fun 😛

What is a Qualifier?

According to the MSDN web site, this is the definition of a WMI qualifier:

 

A qualifier is a data string that provides more information about a class, instance, property, method, or parameter.

 

Using my words, I would say that A WMI qualifier is a something like an attribute that will give additional information to our property. Every property can have one or several property qualifiers, but it should have at least one.

Technically, you can create a property within a class without any property qualifiers, but you wont be able to instanciate that class. In order to Instanciate a WMI class, you will need to have a something that is called a key qualifier.

A Key qualifier, could be compared to a primary key for example in SQL. This value needs to be given, and is the first source of our information. Key qualifiers are not the only qualifier that we can have, there are actually A LOT more. but for we will focus primarly on the key qualifier to keep things simple, since the principle is actually the same. Once you understood the concepts (which are not so hard heh^^) behind the Key qualifier, then you will have understood all about qualifiers. 🙂

[important]Qualifiers can be CIM or WMI specefic[/important]

How to work with wmi qualifiers?

lets look up the cmdlets we have to work with qualifiers:

qualifier powershell commands

 

we have 4 cmdlets that we can use in order to work with qualifier in the wmi-commands module.

  • Get-WMIKeyqualifier
  • Get-WMIQualifier
  • Remove-WMIQualifier
  • Set-WMIQualifier

Their names are pretty straitght forward, so I suggest we go foward and deep dive right into the interesting stuff!

How to find a wmi qualifier?

To find a property qualifier with the default powershell cmdlets I have to say that it is not really that easy.Thats why I actually wrote the WMI module. To retrieve information about property qualifiers you should use Get-WMIQualifier. Let’s look at the “path” property from the win32_share class. For that, we will use the following command:

This will return us the following information:

wmi qualifiers win32_share

 

We can see that for the path property, we have 3 qualifiers that are returned using the get-wmiqualifier cmdlet.

To make it more readible, we will filter the query and only display the qualifier names using the following command:

qualifier information on path property of win32_share


The following 3 qualifiers are actually on the property “path”:

  • CIMTYPE
    Technet definition: Contains text describing the type of a property.
  • MappingStrings
    Technet definition: Set of values that indicate a path to a location where you can find more information about the origin of a property, class, association, indication, or reference.
  • Read
    Technet definition: Indicates whether the property is readable. The default is TRUE.

So as I mentionned earlier, the WMI qualifiers are something that could be compared to attributes that we find in the filesystem. It gives us extra information on the item that we are retrieving the qualifier from.

Let’s get another example and dig into the “Name” property of the same “win32_share” class.

The following results will be returned:

get-wmiqualifier

Here we will find the following same qualifiers as before:

  • CIMTYPE:
    Technet definition: Contains text describing the type of a property.
  • MappingStrings:
    Technet definition: Set of values that indicate a path to a location where you can find more information about the origin of a property, class, association, indication, or reference.
  • Read:
    Technet definition: Indicates whether the property is readable. The default is TRUE.

and two new ones:

  • Override:
    Technet definition: Parent class or subordinate construct (property, method, or reference) which is overridden by the property, method, or reference of the same name in the derived class. The default is NULL.
  • Key:
    Technet definition: The Key qualifier indicates whether the property is part of the namespace handle. If more than one property has the Key qualifier, then all such properties collectively form the key (a compound key). When taken together, the key properties must supply a unique reference for each class instance. If this qualifier is placed on a property, only the value TRUE is allowed.

 

In other words, the key qualifier identify the unique(s) properties that HAVE to be set when you want to instanciate a class. There wasn’t a key property for the path property, but there is one for the name property.

Let’s finalize this with a last example and let’s look at the qualifiers of the description property of the same win32_share class.

We have the following qualifiers for the description property:

win32_share description qualifier

  • CIMTYPE:
    Technet definition: Contains text describing the type of a property..
  • Read:
    Technet definition: Indicates whether the property is readable. The default is TRUE.

As you can see, whe have no key qualifiers for the Description property. And this is actually very logic, and will tell you why I actually choose the description property.

When you create a normal filesystem share, on a server or even on your own personal laptop, we need to provide it with a name AND a path. IF we want, we can add a description to it, but it is NOT obligatory. We could have a share without description. BUT we will always need to give a name to our share. A share without a name is actually not even a share. How would you refer to it? Also, the name of the share has to be unique. The name of the share will be the property that you will use in order to differenciate them from each other. It is a unique property. When we want to create a new share (create an instance of the win32_share, or “instanciate” it, we will need to provide a unique name for the share name. Technically, a folder (path) on a file system can have several shares (name) but each of this share has to be unique.

[important]Point 1:To sum up, the key property of a class, is the property that needs to be set, in order to create a new instance of it. Remeber, try to create a share without giving it a name; Windows will never let you finish it without you giving that parameter. The same principale occurs when you want to created a new instance of WMI class.[/important]

[important] Point 2: The key qualifier has another very important role, and it is again related to the instanciation. When the intanciation is done, the value of the key property will also be used in order to generate the path to the WMI instance. The value of the key property It will be contained in __PATH and in the __RELPATH system properties. I will explain this in the chapter concerning instances.[/important]

How to get a wmi key property with powershell?

Ok great!, now that we know that, we can go on and start to dig deeper in the qualifiers possibilities. Yes, but I have a bonus here for you 😉
Sometimes, you will need to find the property key(s) of a class in order to create a new instance of it. You can either use the code I wrote above in order to find the key(s) or make your life simple and use the Get-KeyQualifier

The returned results are the following ones:

win32_share key qualifier

We can see we receive an object of the key qualifier of the win32_share class. As before, the key qualifier is the property with the name “name

[notice]Remember, to find the key qualifier of specefic class, use the Get-WMIKeyQualifier [/notice]

How to create a new custom WMI Property qualifier with powershell?

Now that I explained what a WMI qualifier actually is, and why it is used for, let’s continue on our previously created example (the PowershellDistrict class) and let’s add a key qualifier to one of our existing properties.

Remember, IF we want to create and instance of our WMI class (Which is actually not even necessary), then we need to have at least one KEY qualifier.

In order to add a wmi property qualifier to an existing WMI property you will want to use the setwmipropertyqualifier cmdlet as showed in the example below.

The cmdlet is pretty straitght forward, use it as followed in order to add a key qualifier to the url property:

 

how to set a key qualifier

It returns all the key(s) that are currently assigned to the property (and our key qualifier as well).

 

How to remove a WMI Property qualifier with powershell?

In order to remove a qualifier we will use the remove-WMIQualifier cmdlet as followed:

There is one caveat when we want to delete a qualifier, is that the class needs to no instance. If there is one or more, they need to deleted before the removal of the qualifier can really be done. If instance(s) are present, the following behaviour will happen.

instance present

To avoid this, the instances need to be removed first. We have not seen the WMI instances yet, but the following cmdlet will allow to delete them;

 

 

The following type of info is returned (the \\CM01 etc… was the RELPATH to the instance that was named “Plop“)

remove all instances

 

After deleting the instance(s) we can now delete the qualifiers with the previous command as showed underneath.

remove a wmi qualifier from a property

Download:

The download link is available hereunder.

[important]Download (and rate by clicking on the stars) the powershell WMI module here .[/important]

 

Dig more into it (References):

Standard qualifiers:

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

Standard WMI qualifiers:

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

Key qualifier:

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

WMI qualifiers

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

 

Ok, that is all for today. I will see you tomorow for new adventures and we will go through WMI instances.

Salut!

 [/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

wmi properties powershell: How to manage them [WMI Week – Day 4]

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]

How to manage WMI class powershell [WMI Week-Day 3]

This is the 3th 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 (this one) highlights how we can, create, retrieve delete, and manage WMI classes.  The fourth post  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]

Rock steady ? let’s jump into it!


Haaa, Switzerland, what an amazing country. It has so much to offer. The people are extremly open minded, they have beautifull landscapes (See picture in WMI Week Day 2 for a for a concrete proof). They have those cool Swiss army knifes that help you to achieve all kind of tasks at home, in the woods, and perhaps even in space! (I actuallywrote a bitlocker encryption tool that works like a swiss army knife. check it out here ! –> Bitlocker swiss army knife script).

I talked about landscapes, I talked about swiss army knifes, but I didn’t mentionned the chocolate yet. Well let me tell you, it is A-MA-ZING !!
As a matter of fact, the company I work for has his main office just right above one of the best chocolate stores in town, and every morning, but I really mean EVERY MORNING,I pass in front of the store and this what I see before entering our building.

Powershell choclat gives you enegery

Swiss chocholat store at the bottom of our building

sometimes, it is reaaaaly difficult to resist the temptation.. 😉

Anyways, why are we here again for? ho yeah, WMI Classes. 3,2,1 GO!

 

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

  • How to retrieve information from a custom WMI class?
  • How to create / add a new WMI class?
  • How to edit a WMI class?
  • How to delete / remove a wmi class?

How to use powershell to find WMI classes?

What we will start by doing is to search for cmdlets that we can use in order to work with classes using the following command:

Get-wmicommand class

In this today’s post, we will focus on the following cmdlets:

  • Get-WMIClass
  • New-WMIClass
  • Remove-WMIClass

 

Let’s explore the possiblities of the Get-WMIClass cmdlets.

WMI cimv2 list

Using the Get-WMIClass cmdlet without any parameters will return you a huge list of classes. This list is actually the content of the “Root\cimv2” namespace, which is Powershell’s default WMI entry. It contained as showed in the below screen shot 1291 classes (on a Windows 8.1 machine).

Get-wmiclasscount

 

[notice]It is important to know that this amount can vary from system to system depending on what has been installed on the machine. The count doesn’t differenciate system properties from the regular classes.[/notice]

If we want to have more information on let’s say the Win32_share class, we would write something like this:

(Here, the use of -namespace is not necessary since Win32_share is located in “Root\cimv2”  which happends to be default namespace of all of the cmdlets located in the WMI module 2.0.)

getwmiclassshare

This will return all the properties, methods qualifiers that the class contains. BUT, it does NOT return the instances of the Win32_share.

[important]The properties that are returned here could be seen as something similar to a blueprint: Once we will instanciated it, we will have this list of properties that we will be able to use. The methodes here though can be used to execute different actions on the current instances that are already present. [/important]

[notice]If you want to return the current present instance, in this case, the real shares currently present on the machine, you can use either Get-WMIClassInstance that is present in the WMI module, that will be covered in a later step, or the good old Get-WMIObject -class Win32_Share.[/notice]

How to create a new custom WMI class powershell?

Now that we have identified how we can get information about classes, let’s create our own one. You know which cmdlet we will need to use for that?

New-WMIClass is Correct! 😉

So, now that have create that first WMI NameSpace called “District“, let’s go ahead with this logic, and create our class directly in that namespace. Let’s name our custom WMI class with powershell to “PowerShellDistrict“. To achieve this, we will use the following small script:

The following will be returned:

create a new wmi class with powershell

Let’s check what we actually created using Get-WMIClass.

freshly create WMI class using powershell

As the screen shot shows, it created the “PowerShelldistrict” class in the “Root\District” namespace. We can also see that the class has currently neither any methods, nor any Properties.
This class will the be used in our next posts on how to create WMI properties and qualifiers.

How to remove a WMI class with powershell?

Let’s say we want to delete our powershelldistrict wmi class with powershell, what cmdlet will we need to use? Correct! The Remove-WMIClass.

We wil use the following command to delete the class:

The result would be the as the following:

remove-wmiclass

 

In green, we see the built-in mecanism that asks for confirmation before deleting the property. In red the result.

[notice]For the purpose of my demonstration and the next sessions of the “WMI week“, I recreated the PowerShellDistrictClass so that we see how we can manage properties with PowerShell.[/notice]

Need more details ? check out the video that summerizes this page right here!

 

 

Ok, that is all for today. Let’s meet tomorrow again where I will go through how we can create, delete and modify WMI properties.[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]