-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHomeDriveCleanup.ps1
36 lines (34 loc) · 1.59 KB
/
HomeDriveCleanup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# ********************************************************************************
#
# Script Name: HomeDriveCleanup.ps1
# Version: 1.0
# Author: Sheridan Wendt
# Date: 9/11/2017
# Applies to: Folders
#
# Description: This script queries Active Directory for a list of disabled users
# then checks a root folder, such as a directory containing user folders
# and if there is a folder name that matches a user in the disabled list it gets
# archived. The process is repeated if there is a directory defined for the
# $AppRoot variable. If a folder gets archived an entry is added to a log.
#
# ********************************************************************************
#Set variables
$HomeRoot = "\\FileServer\users"
$AppRoot = "\\AppServer\Users"
$HomeArchive = "\\FileServer\HomeArchive"
$AppArchive = "\\FileServer\AppArchive"
$list = (Search-ADAccount –AccountDisabled -UsersOnly).SamAccountName
$HomeDriveCleanupLog = "\\FileServer\HomeArchive\log.txt"
#Archive folders of disabled users and log
foreach($User in $List)
{
$DTStamp = get-date -Format u | foreach {$_ -replace ":", "-"}
$Path = Join-Path $HomeRoot -childpath $User
Move-Item $Path $HomeArchive -Force
Add-Content "$HomeDriveCleanupLog" "$DTStamp | $User's Home Drive archived to $Path"
$Path2 = Join-Path $AppRoot -childpath $User
Move-Item $Path2 $AppArchive -Force
Add-Content "$HomeDriveCleanupLog" "$DTStamp | $User's App Drive archived to $Path2"
Add-Content "$HomeDriveCleanupLog" "_______________________________________________________________________________________"
}