0phoi5 Posted January 23, 2018 Share Posted January 23, 2018 (edited) 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 January 23, 2018 by haze1434 Quote Link to comment Share on other sites More sharing options...
PoSHMagiC0de Posted January 23, 2018 Share Posted January 23, 2018 Add a "_" after the "$". Get-WMIObject -Class Win32_UserProfile | where {($_.LocalPath -eq 'C:\Users\JoeBloggs')} Quote Link to comment Share on other sites More sharing options...
0phoi5 Posted January 23, 2018 Author Share Posted January 23, 2018 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 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 Quote Link to comment Share on other sites More sharing options...
PoSHMagiC0de Posted January 24, 2018 Share Posted January 24, 2018 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()} Quote Link to comment Share on other sites More sharing options...
0phoi5 Posted January 24, 2018 Author Share Posted January 24, 2018 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 :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.