This is the 1th 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. Check out the introduction of the WMI week here.

The first gives a short introduction concerning WMI, and show what tools are usefull when working with WMI. The second post (This one) 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 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]

 


Today is a nice and sunny day. This type of weather sometimes makes me want to go out and work outside, in front of the Rhine here in Basel / Switzerland.But unfortunatley even though I recently set up EMS via Configuration manager 2012 with intune integration, which would allow me to take my Android Samsung Galaxy tab 3 tablet and work sitting in front of the river, It is a bit chilly outside, and working there for more then 30min will probably have a direct bad influence on my health. Talking about Configuration manager 2012, the CU3 just got published. If you haven’t downloaded it yet, you can get it here.

Today is also the day that I passed the 70-243:Configuration Manager : Administering and deploying certification exam. So the CU3, the weather, and the exam are perfect ingredients for a great soup that we could name “very good day” 🙂

By the way,I got a bit warmer, and I decided to go to the river for lunch today. Find here a picture I took of the Rhine, which is just around the corner 🙂 Enjoy!

basel_Pano

Basel center (1min from work ;))

 

In  today’s post, I will explain how we can leverage PowerShell in order to create custom namespaces in our WMI repository. To make things easy, this will be done with the WMI powershell module. Here is the agenda:

  • How to find WMI cmdlets information.
  • How to get WMI namespace information.
  • How to create a WMI namespace.

How to find commands to manage WMI namespace with powershell:

First thing first, let’s load the module and see what cmdlets are available for us to use :

The following screenshots shows what has been returned.

wmi namespace powershell

 

  • Get-WMINameSpace
  • New-WMINameSpace

Now, which one of these two commands would you use in order to create a new wmi namespace.. ? 😉

Obviously, you will not use get-wminamespace to create something (will ya ? 0_o)

How to find WMI namespace PowerShell? 

In order to find what WMI namespaces we have on our system will use Get-WMINameSpace.

Let’s use Get-WMINamespace and discover what WMI namespaces are present on my machine.

We want to create a WMI namespace called “District” in the root of our WMI repository (yes, the root, not the Root\Cimv29.

The following screenshots show the current WMI nameSpaces that are present in the root ot the WMI repository of my machine.

 

get-wminamespace

 

[notice]The results that are returned can vary depending on the different installation that has been done (Bitlocker, custom wmi namespaces, specefic programs etc…[/notice]

How to create custom wmi namespaces Powershell?

Now that we know what namespaces are present, let’s go and try to create a wmi namespace using the “New-WMINamespace” cmdlet.

[important] The PowerShell console must run in elevated mode in order to be able to create a WMI namespace.[/important]

new-wminamespace district

 

We can see that if we recall the get-wminamespace command, we will see our new wmi namespace present.

get-wminamespace

 

How to get a wmi namespace with powershell?:

We can dig more into the the namespace by retrieving the namespace directly using the following command:

Powershell will return the following results:

result of get-wminamespace

The results show the default WMI system classes wich start with the double underscore “__” and also te name of the WMINamespace which in this case is “District“.

 

 

Want more details ? Check this video on how to create a custom wmi namespace.

find here a short video explaining how to create a custom wmi namespace.

Dig more into it! (Referrences):

NameSpaces –> http://msdn.microsoft.com/en-us/library/aa822575(v=vs.85).aspx

Ok, that is all for today. Tomorrow, we will talk about custom wmi classes.

A bientôt !  :)[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

By | 2016-10-19T21:00:15+00:00 September 23rd, 2014|module, WMI, wmi module, WMI Week|8 Comments

About the Author:

Stéphane is a dynamic and passionate Cloud and datacenter Microsoft MVP since. He is the founder of the Basel PowerShell user Group (BPUG), the co-founder of the French Speaking PowerShell UserGroup (FRPSUG), author, blogger, and received the community award "PowerShell Hero" from PowerShell.org. Stéphane has implemented microsoft infrastructure solutions in various countries of Europe and is currently working in Basel / Switzerland. Stéphane help his clients to reduce their global infrastructure costs by implementing Microsft infrastructure solutions by combining great products such as System Center, Windows Server, with heavy automation using Windows PowerShell. Stéphane loves languages, Belgium beer, French cheese and French Wine. If any of these topics are of your interest, don't hesitate to come and say hi.

8 Comments

  1. […] WMI Week – Day 2: Namespaces […]

  2. […] WMI Week – Day 2: Namespaces […]

  3. […] WMI Week – Day 2: Namespaces […]

  4. […] WMI Week – Day 2: Namespaces […]

  5. […] WMI Week – Day 2: Namespaces […]

  6. Mike` September 24, 2014 at 12:40 pm - Reply

    I have files extracted to C:\users\Documents\WindowsPowerShell\Modules\WMI-Commands
    when I run import-module WMI-Commands

    I am getting the following error:

    import-module : The specified module ‘WMI-Commands’ was not loaded because no valid module file was found in any
    module directory.
    At line:1 char:1
    + import-module WMI-Commands
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (WMI-Commands:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

  7. Stephane September 23, 2014 at 5:54 pm - Reply

    Hello Mike,

    You should have a text file contained in the downloadable zip file explaining the install instructions. (For recap, this is what should be in it : “Copy the .psm1 and the .psd1 to the following path
    C:\users\\Documents\WindowsPowerShell\Modules\WMI-Commands\ (You might need to create the path if it is not already existing.”)

    Replace by your current loged in account name (open a powershell prompt and type “whoami”).
    The two files must be in the WMI-Commands folder wich should be in the Modules folder.

    Import the module like this:
    import-module WMI-Commands

    Or, if this doesn’t work, you can try giving the direct path to the .psm1 file as showed underneath:
    import-module “C:\Users\Stephane\Documents\WindowsPowerShell\Modules\WMI-Commands\WMI-Commands.psm1”

    Once you have this command working, you can start using the module using “Get-wmiCommands” to see the available commands.

    Stéphane

  8. Mike` September 23, 2014 at 5:34 pm - Reply

    Where do I need to import the module from? C:\Users\USER\Documents\WindowsPowerShell\Modules\WMI-Commands???
    I am getting import-module : The specified module ‘wmi-commands’ was not loaded because no valid module file was found in any

    I have both files in a directory?

    Thank you,

Leave a Reply

%d bloggers like this: