Please help me get the correct code for deleting the User local profile with specific naming convention .
Ex. I want to delete user names logged in with abc_xyz while abc_ is constant and xyz will have different names of users.
My code is :
Get-WMIObject Win32_UserProfile |where-object {$.localpath -like "c:\users\abc*"}
But i do not get it right also i am not able to delete these profiles.
Please help. !
OK But how do i get all the logged in user details in $user .
I mean to say There are many users logged in with ID similar to abc_xyz123 also with other names such as doma500 or sa_account
Among all I need to filter only users whose profile begins with “abc_” and delete it .
Please get me some help please.
Remove-WmiObject : Cannot bind parameter ‘InputObject’. Cannot convert value “C
:\Users\Microsoft.PowerShellISE_
profile.ps1” to type “System.Management.ManagementObject”. Error: "Invalid para
meter "
At C:\Users\Untitled2.ps1:4 char:31
If you just tried to copy/paste that code and ran it, then please be really careful.
I think it is not working is because I left the -computername parameter in the get-wmiobject.
Running code you do not fully understand what its doing can cause major issues. So please in the future, read through the code. Try and understand what its doing, and evaluate the risk.
If you don’t understand it, then ask us here. I am sure people here will be more than happy to help you understand the code.
There are pre-built scripts via MS website and this site as well as others which cover this use case.
However, I cannot over emphasize to you enough what has been already said. Don’t just arbitrarily run anyone’s code you do not fully understand in a production environment, and even in test be cautious and test on systems which you don’t mind destroying or having issues on. Meaning ones you may have to rebuild if you get it wrong.
You should really take a quick PowerShell online course using Microsoft Virtual Academy, before doing any real work with PowerShell, especially this sort of thing, so, that you have a real baseline understanding. It’s good to experiment, but experiment in a safe zone.
Simple search for training using your favorite search engine