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.
>$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
[wmi]win32_process
[wmiclass]win32_process
for more WMI info and examples :
http://thepowershellguy.com/blogs/posh/archive/tags/WMI/default.aspx
Greetings /\/\o\/\/
http://thePowerShellGuy.com
"Hal Rottenberg" <halr...@gmail.com> wrote in message
news:1183399536.3...@q75g2000hsh.googlegroups.com...
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
Thanks /\\/\\o\\/\\/!
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
> 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?
> See how it works now?
>
Yep, thanks for your example.
--
greetings
dreeschkind
# 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?
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
------------------------------------------------------