This script will find all home drives and for each test if the AD user still exists. If it doesn't, it will gather the folder size and output that with the user ID to a text file. Good one for general housekeeping.
-----------------------------
#Compare all H drive folders to AD user accounts.
#If no match is found output a file with the user name and folder size in MB.
#Add all folders found and output total at the end
$HomeDriveFolders = Get-ChildItem -path "H:\Users" | select -expandproperty Name
$totalsize = 0
foreach($folder in $HomeDriveFolders)
{
$user = ""
$user = $(try {get-aduser $folder | select -ExpandProperty SAMACCOUNTNAME} catch {$null})
if ($user -ne $folder)
{
$foldersize = (Get-Item "H:\Users\$folder").GetFiles() | Measure-Object -Sum Length
$foldersize = [math]::Round($foldersize.sum / 1MB)
$totalsize = $totalsize + $foldersize
"$folder,$foldersize" | out-file H:\usercomparisonexport.txt -append
}
}
"---------------------((TOTAL))",$totalsize | out-file H:\usercomparisonexport.txt -append
Wednesday, May 11, 2016
Thursday, February 4, 2016
Disk Cleanup Missing Server 2008 and Later
There is plenty of info out there about how to go about getting to Disk Cleanup (cleanmgr.exe). This is just a quick little batch file to restore it. You do have the option of installing the Desktop Experience features through Server Manager. I personally don't like that option because of the junk that comes with it. Try this out instead...
////////////////////////
Copy and Paste into notepad, save as "AddDiskCleanup.bat"
xcopy "C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe" "%systemroot%\System32"
xcopy "C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui" "%systemroot%\System32\en-US"
cleanmgr.exe
///////////////////////
From this point on you can simply go to start > run > cleanmgr.exe
////////////////////////
Copy and Paste into notepad, save as "AddDiskCleanup.bat"
xcopy "C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe" "%systemroot%\System32"
xcopy "C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui" "%systemroot%\System32\en-US"
cleanmgr.exe
///////////////////////
From this point on you can simply go to start > run > cleanmgr.exe
Subscribe to:
Posts (Atom)