Manage user profiles

Home Forums Scripting PowerShell Manage user profiles

This topic contains 4 replies, has 5 voices, and was last updated by  wullieb1 1 week, 4 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts

  • 12man
    Participant
    #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?


    Ossian
    Moderator
    #191883

    Npt sure of the details, but will Remove-wmiobject remove the actual profile (folder on the PC) or just the entry in the WMI database?


    bas21
    Member
    #391930

    Thanks 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.RemoveWmiObject


    MikesTooLz
    Participant
    #609433

    I just use the delprof2 program and you can easily specify to remove profiles older than x days and also exclude certain accounts.


    wullieb1
    Moderator
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.