Get-WMIObject Delete Method

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #5731

    by Nobody at 2013-03-27 15:52:53

    I created a script to delete profiles on remote computers using the Delete() method of the WMI Object, however Get-Member does not show the delete method. I know it works, but short of someone telling it's there, how would I otherwise know(see) that the delete method is available? This also seems to be the case for deleting printers and I assume other WMI Classes.


    get-wmiobject -query "SELECT * from win32_userprofile WHERE LocalPath LIKE `"%SomeUser`""|Get-Member

    by DexterPOSH at 2013-03-27 16:08:26

    If you hit up the documentation for the class Win32_UserProfile on MSDN.
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee886409(v=vs.85).aspx

    similarly for Win32_Printer class:
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx

    I don't see the delete method here too.

    by proxb at 2013-03-27 18:16:46

    Try this to view the Delete() method.
    (gwmi win32_userprofile)[0].psbase | gm

    by Nobody at 2013-03-28 10:42:26

    Thanks!

    by DexterPOSH at 2013-03-29 11:21:21

    [quote="proxb"]
    (gwmi win32_userprofile)[0].psbase | gm[/quote]

    Thanks Proxb.
    Ok, this method comes wrapped on the PSbase....I need to study up this.

    by Nobody at 2013-03-29 12:04:10

    This article summed up psbase up pretty well for me. I feel like I graduated PS kindergarten now 😀

    http://blogs.technet.com/b/heyscripting ... group.aspx

    [quote]
    Yet another good question: what the heck is that PSBase stuff? Well, when you use Windows PowerShell to connect to an object, PowerShell will often decide, in advance, which methods and properties will be exposed to you. That’s usually fine, except that sometimes PowerShell guesses wrong; sometimes it fails to show the property or method you really need. That’s the case here; if you bind to a local group account (like the Administrator account) PowerShell exposes only a handful of methods and properties:

    ...SNIP...

    That’s where the PSBase object comes in. PSBase lets you get at the “raw” object behind the object PowerShell exposes by default; in other words, PSBase lets you get at all the properties and methods of the object:
    [/quote]

    by DexterPOSH at 2013-03-29 16:38:16

    [quote="Nobody"]This article summed up psbase up pretty well for me. I feel like I graduated PS kindergarten now 😀

    http://blogs.technet.com/b/heyscripting ... group.aspx[/quote]

    Scripting Guy's blog is the first place to start obviously 🙂
    Not much of a surprise, but that article was amongst one I had lined up to read.
    Thanks for sharing it.

You must be logged in to reply to this topic.