Shutdown machine via scheduled task

Reading Time: < 1 minute

The below script will create a schedule task to shutdown the machine at 17:00 daily with a message of “This computer will shutdown in sixty (60) seconds. Please save your work now.”

Copy the below script into a notepad file and rename to something suitable such as shutdown.bat

If you wish to push out the script add the .bat file to computer startup within your group policy. (You may need to reneter speech marks (“) within the script.

SETLOCAL ENABLEDELAYEDEXPANSION

SET strShutdownPath=%SystemRoot%\System32\
SET strShutdownProgram=shutdown.exe
SET strShutdownComment=This computer will shutdown in sixty (60) seconds. Please save your work now.

IF EXIST “%SystemRoot%\System32\schtasks.exe” (
    ECHO Task Scheduler Found, Executing Command…
    ECHO:
    SCHTASKS /Create /RU “SYSTEM” /SC “DAILY” /TN “Computer Shutdown” /TR “%strShutdownPath%%strShutdownProgram% -s -t 60 -c \”!strShutdownComment!\” -f” /ST “18:00:00” /SD “20/09/2010”
    EXIT
) ELSE (
    ECHO Task Scheduler NOT Found, Ending Script…
    EXIT
)

Remove all local profiles with exceptions

Reading Time: < 1 minute

Copy the below code to notepad and rename as a vbs file. Example – DeleteLocalProfiles.vbs. If the script does not work, re-enter the speech marks ( ” )

Const LocalDocumentsFolder = “C:\Documents and Settings\”

set objFSO = createobject(“Scripting.FileSystemObject”)
set objFolder = objFSO.GetFolder(localdocumentsfolder)

on error resume next

for each fldr in objFolder.SubFolders
 if not isexception(fldr.name) then
  objFSO.DeleteFolder fldr.path, True
 end if
next
Function isException(byval foldername)
 select case foldername
  case “All Users”
   isException = True
  case “Default User”
   isException = True
  case “LocalService”
   isException = True
  case “NetworkService”
   isException = True
  case “Administrator”
   isException = True
  case Else
   isException = False
 End Select
End Function

Remove Local Profiles Via Script

Reading Time: < 1 minute

If you wish to remove a selected number of local profiles via script but not all, for example remove all local profiles starting with 80 or 90 or pc etc, you can use the below script as a bat fileand run on system startup or shutdown via group policy.

Please note, deleting local profiles will also delete the my documents folder within the profile unless you have my documents folder redirection configured.

@echo off
c:
cd\documents and settings
for /f %%f IN (‘dir /b 10*; dir /b 11*; dir /b 12*;) DO rd /s /q %%f

Change the numbers 10, 11, 12 as required. The above script will delete local profiles starting with 10, 11 or 12.

Exchange 2007 – number of emails sent and received internally

Reading Time: < 1 minute

Using Exchange Powershell you can run the below command to obtain the number of emails sent internally between users. The below script will output the results into a text file and store it on disk C.

Amend the code as required. Amend @domain.com to your internal domain and the dates you require the report running. Please note that the script may take a while to run if you decide to extend the dates.

get-messagetrackinglog -ResultSize unlimited -Start “01/04/2010 00:00:00” -End “30/04/2010 23:59:00” | where {$_.Sender -like “*@domain.com“}  | where {$_.Recipients -like “*@domain.com“} > “C:\emailcount.txt”

If you are copying and pasting the above code, you may need to re enter the speech marks ( ” )