Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support Forum Windows 8 Forum Vista Tutorials

Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Vista - [WMIClass] versus get-wmiobject


 
 
07-02-2007   #1 (permalink)
Hal Rottenberg


 

[WMIClass] versus get-wmiobject

Can someone explain why these two statements produce different results
and what it means?

1# $a = get-wmiobject win32_process

TypeName: System.Management.ManagementObject#root\cimv2\Win32_Process

2# $b = [wmiclass]"\\localhost\root\cimv2:win32_process"

TypeName: System.Management.ManagementClass#ROOT\cimv2\Win32_Process



They are quite different in that the latter ($b) has a Create() method
which is pretty darn cool.

My System SpecsSystem Spec
07-02-2007   #2 (permalink)
dreeschkind


 

RE: [WMIClass] versus get-wmiobject

Well, I can't explain all the details, but the first statement will get you a
single wmiobject instance for every process that is running
(ManagementObject) and the second statement will get you only one instance of
the corresponding wmiclass (ManagementClass).

>$a.gettype()


IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array

>$a[0].gettype()


IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ManagementObject
System.Management.ManagementBaseObject

>$b.gettype()


IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ManagementClass
System.Management.ManagementObject

--
greetings
dreeschkind

"Hal Rottenberg" wrote:

> Can someone explain why these two statements produce different results
> and what it means?
>
> 1# $a = get-wmiobject win32_process
>
> TypeName: System.Management.ManagementObject#root\cimv2\Win32_Process
>
> 2# $b = [wmiclass]"\\localhost\root\cimv2:win32_process"
>
> TypeName: System.Management.ManagementClass#ROOT\cimv2\Win32_Process
>
> They are quite different in that the latter ($b) has a Create() method
> which is pretty darn cool.
>
>

My System SpecsSystem Spec
07-02-2007   #3 (permalink)
/\\/\\o\\/\\/ [MVP]


 

Re: [WMIClass] versus get-wmiobject

in one case you get a WMI class in the other cave the WMI instances

[wmi]win32_process
[wmiclass]win32_process

for more WMI info and examples :
http://thepowershellguy.com/blogs/po...I/default.aspx

Greetings /\/\o\/\/
http://thePowerShellGuy.com

"Hal Rottenberg" <halr9000@gmail.com> wrote in message
news:1183399536.394147.109570@q75g2000hsh.googlegroups.com...
> Can someone explain why these two statements produce different results
> and what it means?
>
> 1# $a = get-wmiobject win32_process
>
> TypeName: System.Management.ManagementObject#root\cimv2\Win32_Process
>
> 2# $b = [wmiclass]"\\localhost\root\cimv2:win32_process"
>
> TypeName: System.Management.ManagementClass#ROOT\cimv2\Win32_Process
>
> They are quite different in that the latter ($b) has a Create() method
> which is pretty darn cool.
>


My System SpecsSystem Spec
07-02-2007   #4 (permalink)
Hal Rottenberg


 

Re: versus get-wmiobject

On Jul 2, 3:12 pm, dreeschkind <dreeschk...@discussions.microsoft.com>
wrote:
> Well, I can't explain all the details, but the first statement will get you a
> single wmiobject instance for every process that is running
> (ManagementObject) and the second statement will get you only one instance of
> the corresponding wmiclass (ManagementClass).


I was hoping $a[0].Create() would be there but it isn't. I'd still
rather use get-wmiobject if I can just for simplicity's sake but if I
have to do the other way I'd like to know why that is so that I can
explain it to others.

thx

My System SpecsSystem Spec
07-02-2007   #5 (permalink)
Hal Rottenberg


 

Re: versus get-wmiobject

On Jul 2, 3:21 pm, "/\\/\\o\\/\\/ [MVP]" <mow...@hotmail.NoSpam>
wrote:
> in one case you get a WMI class in the other cave the WMI instances
>
> [wmi]win32_process
> [wmiclass]win32_process
>
> for more WMI info and examples :http://thepowershellguy.com/blogs/po...I/default.aspx


Thanks /\\/\\o\\/\\/!

My System SpecsSystem Spec
07-02-2007   #6 (permalink)
dreeschkind


 

Re: [WMIClass] versus get-wmiobject

Is there something wrong with my system?

PS> [wmi]win32_process
Unexpected token 'win32_process' in expression or statement.
At line:1 char:18
+ [wmi]win32_process <<<<

PS> [wmi]'win32_process'
Cannot convert value "win32_process" to type
"System.Management.ManagementObject". Error: "Das angegebene Argument liegt
außerhalb des gültigen Werte
bereichs.
Parametername: path"
At line:1 char:6
+ [wmi]' <<<< win32_process'

--
greetings
dreeschkind

"/\\/\\o\\/\\/ [MVP]" wrote:

> in one case you get a WMI class in the other cave the WMI instances
>
> [wmi]win32_process
> [wmiclass]win32_process
>
> for more WMI info and examples :
> http://thepowershellguy.com/blogs/po...I/default.aspx
>
> Greetings /\/\o\/\/
> http://thePowerShellGuy.com
>
> "Hal Rottenberg" <halr9000@gmail.com> wrote in message
> news:1183399536.394147.109570@q75g2000hsh.googlegroups.com...
> > Can someone explain why these two statements produce different results
> > and what it means?
> >
> > 1# $a = get-wmiobject win32_process
> >
> > TypeName: System.Management.ManagementObject#root\cimv2\Win32_Process
> >
> > 2# $b = [wmiclass]"\\localhost\root\cimv2:win32_process"
> >
> > TypeName: System.Management.ManagementClass#ROOT\cimv2\Win32_Process
> >
> > They are quite different in that the latter ($b) has a Create() method
> > which is pretty darn cool.
> >

>
>

My System SpecsSystem Spec
07-02-2007   #7 (permalink)
Flowering Weeds


 

Re: [WMIClass] versus get-wmiobject


"dreeschkind"

> Is there something wrong with my system?
>
> PS> [wmi]win32_process
> Unexpected token 'win32_process' in expression or statement.
> At line:1 char:18
> + [wmi]win32_process <<<<
>
> PS> [wmi]'win32_process'
> Cannot convert value "win32_process" to type
> "System.Management.ManagementObject". Error: "Das angegebene
> Argument liegt
> außerhalb des gültigen Werte
> bereichs.
> Parametername: path"
> At line:1 char:6
> + [wmi]' <<<< win32_process'
>


PS> get-process notepad

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
42 3 1228 3696 32 0.06 2016 notepad

PS> [wmi]"win32_process.handle='2016'" | select name, handle, __Path |
format-list

name : notepad.exe
handle : 2016
__PATH : \\ServerName\root\cimv2:Win32_Process.Handle="2016"

PS>

See how it works now?



My System SpecsSystem Spec
07-03-2007   #8 (permalink)
dreeschkind


 

Re: [WMIClass] versus get-wmiobject

"Flowering Weeds" wrote:

> See how it works now?
>


Yep, thanks for your example.


--
greetings
dreeschkind
My System SpecsSystem Spec
07-03-2007   #9 (permalink)
Hal Rottenberg


 

Re: versus get-wmiobject

On Jul 2, 3:21 pm, "/\\/\\o\\/\\/ [MVP]" <mow...@hotmail.NoSpam>
wrote:
> in one case you get a WMI class in the other cave the WMI instances
>
> [wmi]win32_process
> [wmiclass]win32_process


# help get-wmiobject

NAME
Get-WmiObject

SYNOPSIS
Gets instances of WMI classes or information about available
classes.
---

Isn't that backwards of what you said? I'm afraid I still don't get
it. I was looking on your site for specific example of using
[wmiclass] and didn't find anything that jumped out at me but I
might've missed the good ones.

Is there a way to use the win32_process.Create() method with get-
wmiobject, or is that just not gonna happen?

My System SpecsSystem Spec
07-03-2007   #10 (permalink)
Jason


 

Re: versus get-wmiobject

> Is there a way to use the win32_process.Create() method with get-
> wmiobject, or is that just not gonna happen?



Hi Hal:

Here's a function to do it which uses get-wmiobject and the -query
parameter:


######################################

function Create-ProcessWithWMI ($computer = ".", $commandline = $(throw
"Enter the command to execute.") )
{
$ProcessClass = get-wmiobject -query "SELECT * FROM Meta_Class WHERE
__Class = 'Win32_Process'" -namespace "root\cimv2" -computername $computer
$results = $ProcessClass.Create( $commandline )

if ($results.ReturnValue -eq 0) { $results.ProcessID } # Or just return
$true if you don't want the PID.
else { $false ; throw "Failed to create process!" }
}

######################################

Cheers,
Jason


------------------------------------------------------
PowerShell Training at SANS Conferences
http://www.WindowsPowerShellTraining.com
------------------------------------------------------


My System SpecsSystem Spec
 

[WMIClass] versus get-wmiobject problems?



Thread Tools


Similar topics to: [WMIClass] versus get-wmiobject
Thread Forum
WMIClass again! PowerShell
WMIClass PowerShell
8.5 versus 2008 versus 9 Live Messenger
Get-WmiObject win32_connectionshare PowerShell
get-wmiobject PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50