Solved

How to purge old roaming profile and redirected mydocs/desktop data for inactive users

Posted on 2014-12-20
1
255 Views
Last Modified: 2014-12-25
On our file server we have a bunch of old profiles and redirected mydocs/desktop folders for users that are no longer active.  Is there an easy way to determine which profile folders have not been used in 'x' days so that we can purge them from primary storage?  We could probably pull a list of AD accounts (both active and disabled) that haven't logged in in 'x' days and cross-reference to the folders on the file server but I'm looking for something less manual.

Thanks!
0
Comment
Question by:River City Bank
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40511373
Powershell Script save as "Get-DeleteProfiles.ps1"
Function Get-DeleteProfiles
{
<#
.Synopsis
   Find inactive users and delete TS Profiles
.DESCRIPTION
   This Script will select Inactive Users from Active Directory and
   delete the profile from the computer
   Modify $daysinactive, $Domain 
.EXAMPLE
   Get-DeleteProfiles.ps1 Computername
.EXAMPLE
   Get-DeleteProfiles.ps1
    Uses Current Computer by Default
#>
[cmdletbinding()] 
param( 
 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] 
 [string[]]$ComputerName = $env:computername 
  ) 
Begin {} 
Process { 
 
import-module activedirectory 
$domain = "domain.mydom.com" 
$DaysInactive = 90 
$time = (Get-Date).Adddays(-($DaysInactive))
 
# Get all AD User with lastLogonTimestamp less than our time and set to enable
$usernames = Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -eq $true} -Properties LastLogonTimeStamp |  select-object Name
 
Write-Verbose ("Working on '{0}'",$ComputerName)
if(Test-Connection -ComputerName $ComputerName -Count 1 -ea 0) 
     { 
    foreach($username in $username)
        {
        $Profiles = Get-WmiObject -Class Win32_UserProfile -Computer $ComputerName -ea 0 
         foreach ($profile in $profiles) { 
         $objSID = New-Object System.Security.Principal.SecurityIdentifier($profile.sid) 
         $objuser = $objsid.Translate([System.Security.Principal.NTAccount]) 
         $profilename = $objuser.value.split("\")[1] 
         if($profilename -eq $UserName)
         { 
             $profilefound = $true 
            try { 
                 $profile.delete() 
                 Write-Host "$UserName profile deleted successfully on",$ComputerName
                 } 
            catch { 
                Write-Host "Failed to delete the profile, $UserName on $ComputerName" 
                } 
        } 
    }
 
     if(!$profilefound) { 
     write-Warning "No profiles found on $ComputerName with Name $UserName" 
     } 
     
     else { 
         write-verbose "$ComputerName Not reachable" 
         } 
        }
    }
 }
end {}
}

Open in new window

sources:
http://techibee.com/powershell/powershell-script-to-delete-windows-user-profiles-on-windows-7windows-2008-r2/1556
https://gallery.technet.microsoft.com/scriptcenter/Get-Inactive-User-in-78b8db79
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question