Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

How to initialize an instance of a WMI System.Management.ManagementClass class

Closed Thread
 
Thread Tools Display Modes
Old 07-19-2007   #1 (permalink)
Clint Bergman
Guest


 

How to initialize an instance of a WMI System.Management.ManagementClass class

Just figured this out and thought it was worth sharing. Should you need to access methods that only exist in the WMI classes themselves and not the instaces (such as the 'Create' method on the Win32_Share class) you can create the object with similar code:

$Win32Share = New-Object System.Management.ManagementClass("Win32_Share")

Lots more information an additional ways in instantiate System.Management.ManagementClass at http://msdn2.microsoft.com/en-us/library/xywtet7d.aspx

I used this info to create shares remotely (was recovering a data volume on a remote server) with:

#Create Network Shares using WMI
param ($Path = $(throw "Missing $Path parameter"),
$Name = $(throw "Missing $Name patameter"),
$Type = 0,
$MaximumAllowed = $null,
$Description = "",
$computer = ".")

$Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
$Win32Share.Create($Path,$Name,$Type,$MaximumAllowed,$Description)

Hope that can be of use to someone
Old 07-20-2007   #2 (permalink)
/\/\o\/\/ [MVP]
Guest


 

RE: How to initialize an instance of a WMI System.Management.Managemen

you can also you the typeexelerator as a shorcut for this :

$win32share = [wmiclass]'win32_share'

enjoy,

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

"Clint Bergman" wrote:

> Just figured this out and thought it was worth sharing. Should you need to access methods that only exist in the WMI classes themselves and not the instaces (such as the 'Create' method on the Win32_Share class) you can create the object with similar code:
>
> $Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
>
> Lots more information an additional ways in instantiate System.Management.ManagementClass at http://msdn2.microsoft.com/en-us/library/xywtet7d.aspx
>
> I used this info to create shares remotely (was recovering a data volume on a remote server) with:
>
> #Create Network Shares using WMI
> param ($Path = $(throw "Missing $Path parameter"),
> $Name = $(throw "Missing $Name patameter"),
> $Type = 0,
> $MaximumAllowed = $null,
> $Description = "",
> $computer = ".")
>
> $Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
> $Win32Share.Create($Path,$Name,$Type,$MaximumAllowed,$Description)
>
> Hope that can be of use to someone

Old 07-20-2007   #3 (permalink)
Clint Bergman
Guest


 

Re: How to initialize an instance of a WMI System.Management.Managemen

Thanks MoW! I'm always trying to do stuff the hard way...

I found a list of Type Shortcuts at http://blogs.msdn.com/powershell/arc...12/663540.aspx but is there a way
to query PowerShell to find out what accelerators are available?
~Clint

"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:447D7366-81A7-44FB-A416-6006DB66DF00@microsoft.com...
> you can also you the typeexelerator as a shorcut for this :
>
> $win32share = [wmiclass]'win32_share'
>
> enjoy,
>
> Greetings /\/\o\/\/
> http://thePowerShellGuy.com
>
> "Clint Bergman" wrote:
>
>> Just figured this out and thought it was worth sharing. Should you need to access methods that only exist in the WMI
>> classes themselves and not the instaces (such as the 'Create' method on the Win32_Share class) you can create the
>> object with similar code:
>>
>> $Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
>>
>> Lots more information an additional ways in instantiate System.Management.ManagementClass at
>> http://msdn2.microsoft.com/en-us/library/xywtet7d.aspx
>>
>> I used this info to create shares remotely (was recovering a data volume on a remote server) with:
>>
>> #Create Network Shares using WMI
>> param ($Path = $(throw "Missing $Path parameter"),
>> $Name = $(throw "Missing $Name patameter"),
>> $Type = 0,
>> $MaximumAllowed = $null,
>> $Description = "",
>> $computer = ".")
>>
>> $Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
>> $Win32Share.Create($Path,$Name,$Type,$MaximumAllowed,$Description)
>>
>> Hope that can be of use to someone



Old 07-20-2007   #4 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 

Re: How to initialize an instance of a WMI System.Management.Managemen

Good question,

I think there is no way to list the type accelerators from PowerShell
all the types in the system namespace are available as shortcuts (you can
leave out system.)
but the accelerators for example those for ADSI and WMI are not listable I
think

As I think this functionality should be there, if I'm right on this file a
feature request on connect and you will get my vote

Greetings /\/\o\/\/

"Clint Bergman" <clint@psd267.wednet.edu> wrote in message
news:ub1cpktyHHA.464@TK2MSFTNGP02.phx.gbl...
> Thanks MoW! I'm always trying to do stuff the hard way...
>
> I found a list of Type Shortcuts at
> http://blogs.msdn.com/powershell/arc...12/663540.aspx but is
> there a way to query PowerShell to find out what accelerators are
> available?
> ~Clint
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:447D7366-81A7-44FB-A416-6006DB66DF00@microsoft.com...
>> you can also you the typeexelerator as a shorcut for this :
>>
>> $win32share = [wmiclass]'win32_share'
>>
>> enjoy,
>>
>> Greetings /\/\o\/\/
>> http://thePowerShellGuy.com
>>
>> "Clint Bergman" wrote:
>>
>>> Just figured this out and thought it was worth sharing. Should you need
>>> to access methods that only exist in the WMI classes themselves and not
>>> the instaces (such as the 'Create' method on the Win32_Share class) you
>>> can create the object with similar code:
>>>
>>> $Win32Share = New-Object
>>> System.Management.ManagementClass("Win32_Share")
>>>
>>> Lots more information an additional ways in instantiate
>>> System.Management.ManagementClass at
>>> http://msdn2.microsoft.com/en-us/library/xywtet7d.aspx
>>>
>>> I used this info to create shares remotely (was recovering a data volume
>>> on a remote server) with:
>>>
>>> #Create Network Shares using WMI
>>> param ($Path = $(throw "Missing $Path parameter"),
>>> $Name = $(throw "Missing $Name patameter"),
>>> $Type = 0,
>>> $MaximumAllowed = $null,
>>> $Description = "",
>>> $computer = ".")
>>>
>>> $Win32Share = New-Object
>>> System.Management.ManagementClass("Win32_Share")
>>> $Win32Share.Create($Path,$Name,$Type,$MaximumAllowed,$Description)
>>>
>>> Hope that can be of use to someone

>
>


Old 07-20-2007   #5 (permalink)
Clint Bergman
Guest


 

Re: How to initialize an instance of a WMI System.Management.Managemen

Suggestion filed on Connect: "List Type accelerators available in PowerShell", thanks for the suggestion on this I often
forget that connect is there.

On a bit of a side note, how is a guy supposed to figure out the syntax to connect to a remote [wmiclass]? I finally
nailed it with trial and error, [wmiclass]\\server\namespace:class, am I just supposed to know the syntax? I couldn't
find anything real helpful on msdn, and knowing how to find the answer is usually my goal. Any tips on how to find info
like that?

Thanks for all your help!
--
(^_^)v ~Clint
My (very) humble blogger beginnings:
http://outputredirection.blogspot.com

"/\/\o\/\/ [MVP]" <mow001@hotmail.NoSpam> wrote in message news:%23AuPw1uyHHA.5376@TK2MSFTNGP03.phx.gbl...
> Good question,
>
> I think there is no way to list the type accelerators from PowerShell
> all the types in the system namespace are available as shortcuts (you can leave out system.)
> but the accelerators for example those for ADSI and WMI are not listable I think
>
> As I think this functionality should be there, if I'm right on this file a feature request on connect and you will get
> my vote
>
> Greetings /\/\o\/\/
>
> "Clint Bergman" <clint@psd267.wednet.edu> wrote in message news:ub1cpktyHHA.464@TK2MSFTNGP02.phx.gbl...
>> Thanks MoW! I'm always trying to do stuff the hard way...
>>
>> I found a list of Type Shortcuts at http://blogs.msdn.com/powershell/arc...12/663540.aspx but is there a
>> way to query PowerShell to find out what accelerators are available?
>> ~Clint
>>
>> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
>> news:447D7366-81A7-44FB-A416-6006DB66DF00@microsoft.com...
>>> you can also you the typeexelerator as a shorcut for this :
>>>
>>> $win32share = [wmiclass]'win32_share'
>>>
>>> enjoy,
>>>
>>> Greetings /\/\o\/\/
>>> http://thePowerShellGuy.com
>>>
>>> "Clint Bergman" wrote:
>>>
>>>> Just figured this out and thought it was worth sharing. Should you need to access methods that only exist in the
>>>> WMI classes themselves and not the instaces (such as the 'Create' method on the Win32_Share class) you can create
>>>> the object with similar code:
>>>>
>>>> $Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
>>>>
>>>> Lots more information an additional ways in instantiate System.Management.ManagementClass at
>>>> http://msdn2.microsoft.com/en-us/library/xywtet7d.aspx
>>>>
>>>> I used this info to create shares remotely (was recovering a data volume on a remote server) with:
>>>>
>>>> #Create Network Shares using WMI
>>>> param ($Path = $(throw "Missing $Path parameter"),
>>>> $Name = $(throw "Missing $Name patameter"),
>>>> $Type = 0,
>>>> $MaximumAllowed = $null,
>>>> $Description = "",
>>>> $computer = ".")
>>>>
>>>> $Win32Share = New-Object System.Management.ManagementClass("Win32_Share")
>>>> $Win32Share.Create($Path,$Name,$Type,$MaximumAllowed,$Description)
>>>>
>>>> Hope that can be of use to someone

>>
>>

>



Old 08-01-2007   #6 (permalink)
Hal Rottenberg
Guest


 

Re: How to initialize an instance of a WMI System.Management.Managemen

On Jul 20, 1:24 pm, "Clint Bergman" <cl...@psd267.wednet.edu> wrote:
> On a bit of a side note, how is a guy supposed to figure out the syntax to connect to a remote [wmiclass]? I finally
> nailed it with trial and error, [wmiclass]\\server\namespace:class, am I just supposed to know the syntax? I couldn't
> find anything real helpful on msdn, and knowing how to find the answer is usually my goal. Any tips on how to find info
> like that?


bump... I'd like to know in particular how you supply credentials to
such a construct as [wmiclass]\\server\namespace:class.

$a = get-wmiobject win32_share -comp server -cred $(get-credential)
$b = [wmiclass]'\\server\root\cimv2:win32_share'

$b is going to fail if I can't supply credentials obviously.

Has anyone come across documentation for this? I'm sure it's buried
on MSDN somewhere.

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Computer management & System Cojo Vista mail 0 06-20-2008 10:28 PM
Windows Easy Transfer - Failed to initialize the logging system Rafal Vista General 2 06-06-2008 09:36 AM
Using New-Object With ManagementClass urkec PowerShell 4 03-06-2008 12:31 PM
Initialize Junk Mail Filtering and MSOE.DLL could not initialize RainbowKid Vista mail 13 03-04-2008 11:36 PM
Issues with System drive in Disk Management on a Dual Boot system =?Utf-8?B?dGhpbHRvbg==?= Vista General 4 07-09-2006 06:26 PM








Vistax64.com 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 2005-2008

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