A
A
Alexander Kaplun2016-04-14 12:26:00
PowerShell
Alexander Kaplun, 2016-04-14 12:26:00

How to clean a disk on a terminal server?

Help who than can,
There is a Windows Server 2008 R2 x64 as a terminal server.
There are not many places and it is constantly running out.
Is there a script that will clean temporary files created by users and the system.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Ethril, 2016-04-14
@Ethril

$OtherCleanPathsArr = "C:\Temp\*", `
"C:\Windows\Temp\*", `
"C:\`$Recycle.Bin\*", `
"C:\swsetup", `
"C: \Windows\System32\*.tmp", `
"C:\Windows\ServiceProfiles\LocalService\AppData\Local\FontCache-S-*.*", `
"C:\Windows\ServiceProfiles\LocalService\AppData\Local\~ FontCache-S-*.*", `
"C:\Windows\*.dmp" #system
paths to clean up
$InProfilesCleanPathsArr = "\AppData\Local\Temp\*", `
"\Downloads\*", `
"\AppData\Local\*.auc", `
"\AppData\Local\Microsoft\Terminal Server Client\Cache\*", `
"\AppData\Local\Microsoft\Windows\Temporary Internet Files\*", `
"\AppData\Local\Microsoft\Windows\WER\ReportQueue\ *", `
"\AppData\Roaming\Microsoft\Word\*", `
"\AppData\Roaming\Microsoft\Excel\*", `
"\AppData\Local\Microsoft\Windows\WebCache\*", `
"\ AppData\Local\Microsoft\Windows\Explorer\*.db", `
"\AppData\Local\Microsoft\Office\15.0\Lync\Tracing\*", `
"\AppData\Local\Apps\*", `
"\AppData\Local\Microsoft\Windows Mail\*" #paths
in profiles to clear
Get-ChildItem -Path \ -Include *.flv, *.mp4, *.wmv, DOMA.DBF, STREET.DBF, KLADR.DBF -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue #deleted
some files directly
$Profiles = Get-ChildItem (Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList").ProfilesDirectory `
-Exclude "Admin", "Administrator", "Setup", "Public", "All Users", "Default User"
#extracted profile location from registry,
ForEach ($Profile in $Profiles) {
ForEach ($Path in $InProfilesCleanPathsArr) {
Remove-Item -Path $Profile$Path -Recurse -Force -ErrorAction SilentlyContinue
}
$temp = ($Profile.FullName + '\AppData\Local\ *.')
#echo $temp
cmd.exe /c "del /Q `"$temp`""
}

R
res2001, 2016-04-14
@res2001

Switch to using RemoteApp, then the terminal server disk is practically not used by users. Especially if you put Windows on the terminal on the Z drive, for example.

J
Janus74, 2016-04-14
@Janus74

I use Delprof2 1.5.4 and
run this script:

reg add "HKLM\SYSTEM\CurrentControlSet\Control\terminal Server" /v TSServerDrainMode /d 0x1 /f /t REG_DWORD
C:\Delprof2\DelProf2.exe /q
shutdown -r -t 600

E
Eugene, 2016-04-14
@yellowmew

1. cleaning up system temporary files:
include in features (components) Desktop Experience (desktop features). Reboot. After the reboot, you get the standard cleanmgr.
1.a configure cleanmgr. command line switches
/sageset:n - configure cleaning profile number n
/sagerun:n - run the configured cleaning profile number n.
and generally read, for example, this or other documentation, on the MS website, for example, and customize it for yourself.
Run cleanmgr with the necessary keys according to the schedule in the task scheduler.
2. Clear user profiles
Enable the group policy setting on this server:

Computer Configuration -> Administrative Templates -> System -> User Profiles
Delete cached copies of roaming profiles

Now, when a user logs off, his profile will be displayed.
There are problems that it is not removed - but they must be solved separately.
You also teach users not to store anything on the desktop-documents of the terminal server, allocate a separate disk / network drive for storing working documents if it is unacceptable to store documents on the user's computer.
Well, you use remoteapp, of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question