Announcement

Collapse
No announcement yet.

Manage user profiles

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Manage user profiles

    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
    ------------------------------------------------------------------------

    My initial script only deals with the user profiles:

    (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?
    Last edited by 12man; 25th November 2017, 15:41.

  • #2
    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?
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      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.C ommands.RemoveWmiObject

      Last edited by 12man; 28th November 2017, 18:15.

      Comment

      Working...
      X