Creating instances

The arguments for Win32_Process, create include a ProcessStartupInformation parameter. ProcessStartupInformation is described by a WMI class, Win32_ProcessStartup.

There are no existing instances of Win32_ProcessStartup (Get-CimInstance), and the class does not have a Create method (or any other constructor).

New-CimInstance can be used to create a class:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = New-CimInstance -CimClass $class -ClientOnly 

New-Object can also be used:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = New-Object CimInstance $class 

Finally, the new method may be used:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = [CimInstance]::new($class)

Properties may be set on the created instance; the effect of each property is documented on MSDN at https://msdn.microsoft.com/en-us/library/aa394375(v=vs.85).aspx.

In the following example, properties are set to dictate the position and title of a cmd.exe window:

$class = Get-CimClass Win32_ProcessStartup 
$startupInfo = New-CimInstance -CimClass $class -ClientOnly 
$startupInfo.X = 50 
$startupInfo.Y = 50 
$startupInfo.Title = 'This is the window title' 

$params = @{
ClassName = 'Win32_Process'
MethodName = 'Create'
Arguments = @{ CommandLine = 'cmd.exe' ProcessStartupInformation = $startupInfo
} } $returnObject = Invoke-CimMethod @params
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.45.137