Jump to content

[PowerShell] - Get-WMIObject filter - The term '$.LocalPath' is not recognized


0phoi5

Recommended Posts

Hi all,

This works fine...

Get-WMIObject -Class Win32_UserProfile | Select -Expandproperty LocalPath

However, the following does not. What am I doing wrong with the syntax here?

Get-WMIObject -Class Win32_UserProfile | where {($.LocalPath -eq 'C:\Users\JoeBloggs')}

 

$.LocalPath : The term '$.LocalPath' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a

path was included, verify that the path is correct and try again.

At line:1 char:50

+ Get-WMIObject -Class Win32_UserProfile | where {($.LocalPath -eq 'C:\Users\JoeBloggs ...

+ ~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: ($.LocalPath:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

Edited by haze1434
Link to comment
Share on other sites

2 hours ago, PoSHMagiC0de said:

Add a "_" after the "$".


Get-WMIObject -Class Win32_UserProfile | where {($_.LocalPath -eq 'C:\Users\JoeBloggs')}

 

Thank you. Doh, silly me, couldn't see the wood for the trees :lol:

I'm now attempting to pipe this to Remove-WMIObject;

Get-WMIObject -Computer $computer -Class Win32_UserProfile | where {($_.LocalPath -eq $profile)} | Remove-WMIObject

But it get...

Remove-WMIObject :

+ ... q $profile)} | Remove-WMIObject

+ ~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [Remove-WmiObject], ArgumentException

+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.RemoveWmiObject

 

Link to comment
Share on other sites

8 hours ago, PoSHMagiC0de said:

I have written a script that does this before.  Remove-wmiobject does not work on it.  I cannot tell you why.  But this will.

 


Get-WMIObject -Computer $computer -Class Win32_UserProfile | where {($_.LocalPath -eq $profile)} | foreach {$_.Delete()}

 

You beauty.

Cheers :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...