Teams computer wide install - batch-file

I'm trying to create a script to populate the existing users folders on a Windows workstation and then do a 'for each' to:
remove the directories
c:\users\%username%\appdata\roaming\Microsoft\teams
and also
c:\users\%username%\appdata\local\Microsoft\teams
in order to completely gut the system of any left over Teams installs.
I already have the script to install computer-wide Teams, plus a PowerShell script to initiate a Teams install for the user as a scheduled task that triggers immediately, (although teams won't work until a reboot for some reason), but I digress.
Currently I only have the removal script for the logged on user, (although it says it cant find the file), but I know this can be done for all users.
ECHO Ensure you are running this while logged on to the account of the user that has issues
ECHO Changing to users AppData folder
CD "%AppData%"
ECHO Removing corrupted Teams Files from User account
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\blob_storage\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\cache\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\databases\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\gpucache\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\indexeddb\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\Local Storage\*.*"
DEL /S /Q /F "%appdata%\roaming\microsoft\teams\tmp\*.*"
PAUSE

You can use the "for" loop in Windows command prompt (cmd.exe) to iterate through all the user folders in the "c:\users" directory, and then use the "rd" command (short for "remove directory") to delete the specified folders.
For example, the script could look like this:
for /d %i in (c:\users\*) do (
rd /s /q "c:\users\%i\appdata\roaming\Microsoft\teams"
rd /s /q "c:\users\%i\appdata\local\Microsoft\teams"
)
The /s switch is used to remove all subfolders and files. /q switch is used to delete files without a prompt confirmation.
Please be aware that, this will delete all files and folders inside the specified directory, including all subdirectories and files, so please be sure you are using the correct directory path before running the script.
remember to have a backup of the entire system before making any changes.

Teams machine wide install:
:: install.bat
:: https://www.reddit.com/r/sysadmin/comments/hzektt/comment/fzje31l/?utm_source=reddit&utm_medium=web2x&context=3
:: machine wide install, ends up being 32-bit
reg add HKLM\SOFTWARE\Citrix\PortICA /f
start /wait msiexec /i Teams_windows_x64.msi /qb ALLUSER=1
set err=%errorlevel%
del "c:\users\public\desktop\Microsoft Teams.lnk"
reg delete hklm\software\wow6432node\microsoft\windows\currentversion\run /f /v teams
exit /b %err%

Related

GPO .bat file not working logoff/shutdown delete files and folder

I am trying to create a simple batch file to delete a folder and/or its contents for a user when they logoff or shutdown.
The GPO itself is working and running, I know this because it first creates a .txt document before running the delete commands.
batch file is called "delete.bat"
The GPO first copies over the batch file to C:\delete.bat. the GPO does this every time all the time.
it is set to run this file on either shutdown or logoff. right now it only runs on shutdown.
i have several versions of this file
echo.>"C:\Users\myactualname\testyoyo.txt
del "C:\Users\%username%\cpsi\data_4\*.*" /s /f /q
#RD /S /Q "C:\Users\%username%\cpsi\data_4\"
exit
.
#echo off
sleep 4
echo.>"C:\Users\myactualname\testyoyo.txt"
sleep 2
set fld=C:\Users\myactualname\cpsi\data_4\
for /f %%a in ('dir %fld% /b /a-d') do echo del "%fld%%%a"
for /f %%a in ('dir %fld% /b /ad') do echo rmdir /s /q "%fld%%%a%"
.
#echo off
echo.>"C:\Users\myactualname\testyoyo.txt"
#echo off
rem Delete all files and subfolders in directory for temporary files
rem of current user account, but keep the directory itself. Temporary
rem files and subdirectories currently in use are silently ignored.
del /F /Q "C:\Users\%username%\cpsi\data_4\*" 2>nul
for /D %%D in ("C:\Users\%username%\cpsi\data_4\*") do rd /Q /S "%%~D" 2>nul
rem Do the same as above for system temporary files directory.
rem This cleanup requires administrator privileges.
del /F /Q "C:\Users\%username%\cpsi\data_4\*" 2>nul
for /D %%D in ("C:\Users\%username%\cpsi\data_4\*") do rd /Q /S "%%~D" 2>nul
i also ran some other version which i haven't documented. I've tried hardcoding the file paths for testing and using the %username% wildcard.
on shutdowns it will create the txt file but not on logoffs. and at no time will it delete the files/folders.
the bat files all run fine if manually run.
i am pretty sure the file permissions are good.
however i suspect permissions is what i suspect is the problem.
thanks!!!

" Access is denied." error while trying to delete TEMP files using batch file

I am trying to delete all my temp files by running below batch file. but unfortunately, i am receiving "Access is denied." error. I am not sure on the root cause or how to minimize this.
#echo off
cd %temp%
for /d %%D in (*) do rd /s /q "%%D"
del /f /q *
Also suggest a way to delete all internet temp files(IE).
The way you're doing it is really dangerous:
cd without /D changes directory but not the drive. So if you run this script from drive D: it will change the current directory of drive C then will proceed deleting everything in your D: drive.
If you are lucky, you don't have permissions on your other drive. If you're not you lose all your files.
You would have needed cd /D %TEMP% to make it safe, but it's even better to avoid to change current directory:
#echo off
for /d %%D in (%TEMP%\*) do rd /s /q "%%D"
del /f /q %TEMP%\*
Of course, temp cleanup can fail because some files are in use by running programs. In that case, just reboot and run the script again.
I just ran this script and now there's 3 dirs and 10 files in my temporary directory (there were a lot of old files before)
To delete temporary IE files, it's slightly different as the directories are hidden so we have to list hidden dirs with a special dir command (the FOR command does not see the hidden directories)
#echo off
set IETEMP=%LOCALAPPDATA%\Microsoft\Windows\INetCache
for /F %%D in ('dir /AHD /B %IETEMP%') do rd /s /q "%IETEMP%\%%D"
del /f /q %IETEMP%\*

Why is my bat script deleting itself when I run it

I have made a bat script as follows
cd "D:\ACT\ACTBKUP"
del /Q *.*
FORFILES /P E:\ACT_Backups /M *.zip /D +1 /C "cmd /c del #D:\ACT\ACTBKUP"
The script is supposed to delete everything in "D:\ACT\ACTBKUP" and then move the newest zip folder to that same folder from E:\ACT_Backups. When I run this script from windows server 2012 it just disappears.
thanks
In order to switch to a directory that is located on a different drive, you need to use cd /d instead of just cd. If you do not do this, the directory will not change.
When you run a script by double-clicking on it, batch considers the current directory to be the directory where the script is currently located. Since you are not using the /d option with cd, you are running del /Q *.* on the directory where the script is located.
To fix this, you have two options:
cd /d "D:\ACT\ACTBKUP"
del /Q *.*
or
del /Q "D:\ACT\ACTBKUP"
There is no option in forfiles to get just the most recent file; /D +1 will return all files with a last-modified date of today or later. In order to get the most recent file and nothing else, you will need a for /f loop:
rem /b returns just the file name and /o:d sorts the files by date
rem Since newest_file gets set for each .zip file in the directory,
rem the last file set will be the newest
for /f "delims=" %%A in ('dir /b /o:d E:\ACT_Backups\*.zip') do set newest_file=%%A
copy %newest_file% D:\ACT\ACTBKUP

Why does my single line batch file require user input on deleting files on a drive?

I am trying to create a batch for a scheduled task to purge a drive every 6 days. The goal is to have it fully automated so I can schedule it and walk away. For some reason my batch keeps asking for user input (y/n) which defeats the purpose.
REM Friday Purge
forfiles /p "G:" /s /m *.* /c "cmd /c Del G:"
Why does my batch file with just a single line (without remark line) require user input on deleting files on drive G: on execution?
The /F switch will force delete a read-only file.
The /Q will prevent the message from popping up.
The /S will delete all files in directories as well.
THE RD will remove a folder.
Therefore; your new code should look like this:
del /f /q /s *.*
del /f /q /s G:
BONUS
If you want this to be automated:
for %%i in (Mon) do (
if "%date:~0,3%"=="%%i" goto yes
)
goto endlocal
:yes
del /f /q /s G:
del /f /q /s G:\*.*
:endlocal
This will check if the day of the week is Monday, and do this once very 7 days. This checks the day and does the schedule part for you; so set it to run everyday.

How can I delete a file from all users' desktops with a batch script?

DEL /F /Q "%AllUsersProfile%\Desktop\Kronos Workforce Central(R).url"
DEL /F /Q "%AllUsersProfile%\Desktop\Kronos Workforce Central(R).website"
DEL /F /Q "%UserProfile%\Desktop\Kronos Workforce Central(R).url"
DEL /F /Q "%UserProfile%\Desktop\Kronos Workforce Central(R).website"
Call %CD%\!Kshort.vbs
I created the above batch file which works well. I plan to execute a mass removal of an old link using LogMeIn. Each system has the same credentials for the Admin account but different for the individual users. Using this method I would need to manually enter the login information for hundreds of computers. Is there a smarter way to perhaps seek out these known file names and remove them without using the %UserProfile% command but still keeping the multi-system flexibility that I need?
Is there a way of deleting files on another user's desktop without knowing that user's name?
Can you remove a file from each and every "Desktop" folder on a computer?
Use the for /f command to loop through all users in C:\Users, then check if the file exists in each users Desktop directory - if it does, delete the file.
for /f %%a in ('dir /B /AD C:\Users') do (
if exist "C:\Users\%%a\Desktop\Kronos Workforce Central(R).url" del /F /Q "C:\Users\%%a\Desktop\Kronos Workforce Central(R).url"
if exist "C:\Users\%%a\Desktop\Kronos Workforce Central(R).website" del /F /Q "C:\Users\%%a\Desktop\Kronos Workforce Central(R).website"
)

Resources