Furthermore, in my project of eradicating Windows XP from the network I have run across instances where users were saving things to their "My Documents" folder (which isn't redirected) instead of to their mapped personal drive (which is the file server that gets backed up). It's a miracle that people haven't lost more data!
What I've done is created a Powershell login script (my first) that collects some key pieces of information and writes to a file on a wide-open share.
#Purpose: Run via Group Policy and give IT data on who has folder redirection turned on, as well as how much data our users have stored locally in their "My Docs" folder.
#Get Computername
$ComputerName = $env:COMPUTERNAME
#Get "My Documents" folder path
$Path = [environment]::GetFolderPath([environment+SpecialFolder]::MyDocuments)
#Define marker file, which prevents this script from running for that user if found
$MarkerFile = "$Path\DELETEME.TXT"
$MarkerText = "TEST"
#Destination Folder to accumulate these files
$Destination = "\\NASDevice\OpenShare\FolderRedir\"
#If the Marker file doesn't exist.....
If ((Test-Path $MarkerFile) -eq $False){
#Make a MarkerFile so this won't run again
$MarkerText | out-file $MarkerFile
#Get Size of My Docs folder, and convert output to GB
$TotalSize = Get-ChildItem -path $path -recurse -errorAction "SilentlyContinue" | Measure-Object -property length -sum
$SizeOutput = "{0:n6}" -f ($TotalSize.sum / 1GB) + " GigaBytes"
#Put the data together
$SubjectInit = "$ComputerName - $Path - $SizeOutput"
$SubjectInit = $SubjectInit.replace("\","-").replace(":",".")
#Create the file with the data, then move the file to the share
New-Item -name $SubjectInit -path $path -itemtype "file"
Move-Item "$path\$SubjectInit" $Destination
} #End If
What this process ultimately does is place a file on an open share that has a filename like this:
COMPUTERNAME - DocFolder - SizeOfFiles
The IF statement at the bottom checks the existence of a marker file. If the file doesn't exist, the process continues and creates the marker file. Otherwise, nothing happens. This is so the login script only creates a file on the open share once per user.
The part that I had to research was how to run a Powershell script on logon. Thankfully, The Scripting Guy had a very helpful post. I even learned about WMI filters along the way!
I'm not going to regurgitate his steps to you. They are clear-cut enough.
Since I'm going to create this marker-file within users' MyDocs folders, when I've collected all the data I need and it's time to unlink this GPO, I'll need to alter the script to delete the marker-file if it exists.
Another tidbit: Powershell logon scripts only run on Windows 7, and not Windows XP logins. I don't know about Vista; we don't run it.
No comments:
Post a Comment