Manage user profiles
Home › Forums › Scripting › PowerShell › Manage user profiles
This topic contains 4 replies, has 5 voices, and was last updated by wullieb1 2 months, 3 weeks ago.
-
AuthorPosts
-
November 24, 2017 at 9:36 am #167314
Group,
I am not versed in PowerShell- still learning.I need to manage Userprofiles on 1000+ computers.
I am starting small.The end goal is to remotely delete User profiles (other than specials) over 5 days old)
This is the ‘rough’ goal
Get-WMIObject -class Win32_UserProfile -ComputerName ‘XXXXX’| Where {(!$_.LocalPath -like ‘**.*’) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-5))} | Remove-WmiObject
[SIZE=14px]My initial script only deals with the user profiles[/SIZE]:(Get-WmiObject Win32_UserProfile -ComputerName ‘XXXXX’ | Where {($_.LocalPath -like ‘**.*’)}|)
This successfully enumerates all profiles that fit the pattern (firstname.lastname)
(Get-WmiObject Win32_UserProfile -ComputerName ‘XXXX’ | Where {($_.LocalPath -like ‘**.*’)}| Remove-WmiObject -whatif)
This lists all profiles that would be deleted- no errors
(Get-WmiObject Win32_UserProfile -ComputerName ‘xxxx
‘| Where {($_.LocalPath -like ‘**.*’)}| Remove-WmiObject)This results in errors…. what am I missing?
November 25, 2017 at 6:24 am #191883Npt sure of the details, but will Remove-wmiobject remove the actual profile (folder on the PC) or just the entry in the WMI database?
November 28, 2017 at 8:18 am #391930Thanks for the response!
Good question– I am not for certain. Regardless, I do need to figure out why it appears NOT to run.Remove-WMIObject :
At line:1 char:107
+ … ke ‘**.*’)} | Remove-WMIObject)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Remove-WmiObject], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.RemoveWmiObjectNovember 30, 2018 at 7:40 am #609433I just use the delprof2 program and you can easily specify to remove profiles older than x days and also exclude certain accounts.
November 30, 2018 at 6:20 pm #609522Try this
https://powershell.org/forums/topic/how-do-i-delete-user-profile/
Or this pre-built script from Technet, please note that i havn’t tried the script
https://gallery.technet.microsoft.com/scriptcenter/Remove-UserProfile-Remove-96e27a3b
If you’re in a domain use GPO??
-
AuthorPosts
You must be logged in to reply to this topic.