Monday, December 24, 2012

Capture a complete Windows Memory Dump


Mentioned steps are to configure the machine for a complete memory dump using a keyboard.

1)    Right click Computers and Select Properties.
2)    Select the Advanced system settings.
3)    Click the "Startup and Recovery" – settings button.
4)    Under the "Write Debugging Information" section select: "Complete

        Memory Dump" from the pull-down menu.

5)    If the Complete memory dump option is not available , then we need to
       change a registry setting.
6)    Open the regedit and navigate to :

        HKLM\CurrentControlSet\Control\CrashControl

        Change the value CrashDumpEnabled to 1

7)   Again open Startup and Recovery tab and you will get the option of

       Complete memory Dump.

8)   Uncheck the option of Automatically Restart.
9)  Make sure a check mark is placed on: "Overwrite any existing file"
10)  Make sure that there is a paging file (pagefile.sys) on the System Drive and it should be atleast 1 GB more than the RAM.
         Right click Computer->Properties. Then select Advanced System Settings.

         In the Advanced tab, select Performance and then settings.

         Select Advanced, click Change under Virtual memory.

         Then select Custom size and then set both the initial and final size to the same value.

11)  Also make sure there is more space on the hard drive than the physical RAM to collect the memory dump.
12)  By default the memory dump is saved on the System Root. If we do not have space on the System root , we can change the location to another drives.

After these settings are checked we need to configure the machine for a keyboard initiated memory dump. Depending on the keyboard used the registry changes are different.

For USB keyboard the settings are:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\kbdhid\Parameters
On the Edit menu, click Add Value, and then add the following registry value:
Value Name: CrashOnCtrlScroll
Data Type: REG_DWORD
Value: 1
Quit Registry Editor.

For PS2 keyboard:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters
On the Edit menu, click Add Value, and then add the following registry value:
Value Name: CrashOnCtrlScroll
Data Type: REG_DWORD
Value: 1
Quit Registry Editor.


After these settings you can reboot the server and then it is configured for a complete memory dump. The keyboard should be directly attached to the server. When the server is in the hung state, we need to hold the right Ctrl key and press Scroll lock key twice. This will bugcheck the machine with the error code Stop E2 and the dump file would be generated.

Refer to the following article:


Friday, December 21, 2012

Error Message " 0x8004100E" When You Run a Windows Management Instrumentation Script


Error Message " 0x8004100E" When You Run a Windows Management Instrumentation Script

c:\wbemtest 

To check WMI connectivity.

Cause:WMI corruption

Resolution:
             C:\Windows\system32>winmgmt /verifyrepository
             WMI repository is INCONSISTENT

             C:\Windows\system32>winmgmt /salvagerepository
             WMI repository salvage failed
             Error code: 0x8007041B
             Facility: Win32
             Description: A stop control has been sent to a service that other running ser vices are dependent on.

             C:\Windows\system32>winmgmt /resetrepository
             WMI repository reset failed
             Error code: 0x8007041B
             Facility: Win32
             Description: A stop control has been sent to a service that other running services are dependent on. 

IT WORKED.

WMI issue was fixed in the server  after applying following steps.

1.            Change startup type to Window Management Instrumentation (WMI) Service to disabled       
2.            Stop the WMI Service, you may need to stop IP Helper Service first before it allow you to stop WMI Service as it is a  dependency
3.            Rename the repository folder:  C:\WINDOWS\system32\wbem\Repository
4.            Open a CMD Prompt with elevated privileges
5.            Cd windows\system32\wbem
6.            for /f %s in ('dir /b /s *.dll') do regsvr32 /s %s
7.              Set the WMI Service type back to Automatic and restart WMI Service
8.            cd /d c:\  ((go to the root of the c drive, this is important))
9.            for /f %s in ('dir /s /b *.mof *.mfl') do mofcomp %s
10.          Reboot the server

The solution was provided by Microsoft PS.

Thursday, December 13, 2012

ASP.NET Temp Files Cleanup


ASP.NET Temp Files Cleanup


@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION

REM Subhag Ghosh , Cleanup ASP.NET temp files

set PARAMETER_COUNT=0
for %%x in (%*) do set /A PARAMETER_COUNT=!PARAMETER_COUNT!+1
IF /I !PARAMETER_COUNT! lss 1 goto:BAD_PARAMETERS

IF NOT EXIST "%~1" goto:BAD_PATH
SET ROOT_DIR=%1
SET INIT_DIR=%cd%

IF /I %PARAMETER_COUNT% lss 2 (
SET IGNORE_NUM=0 
)ELSE (
SET IGNORE_NUM=%2
)

IF /I %IGNORE_NUM% lss 0 goto:BAD_IGNORE_NUM
IF /I %IGNORE_NUM% gtr 10 goto:BAD_IGNORE_NUM


SET LOG_FILE=%INIT_DIR%\ASPNETTempFilesCleanup.log


ECHO Starting folder cleanup...
ECHO %time% Starting folder cleanup... > "%LOG_FILE%"

SET MOTHER_LOOPS=0
SET MOTHER_DELETES=0
SET MOTHER_IGNORES=0
SET MOTHER_DELETE_AMOUNT=0
SET MOTHER_IGNORE_AMOUNT=0

CD /D %ROOT_DIR%

for /f "delims=" %%H in ('dir /AD /B') do (

ECHO Processing folder %%H...

CD /D %ROOT_DIR%\%%H
ECHO !time!        ======================================================================== >> "%LOG_FILE%"
ECHO !time! eSpace: %%H >> "%LOG_FILE%"
ECHO !time! Action Folder Date size >> "%LOG_FILE%"
ECHO !time! -------- -------- ---------------- -------- >> "%LOG_FILE%"
SET CHILD_LOOPS=0
SET CHILD_DELETES=0
SET CHILD_IGNORES=0
SET CHILD_DELETE_AMOUNT=0
SET CHILD_IGNORE_AMOUNT=0
for /f "delims=" %%G in ('dir /AD /B /O-D /TC') do (

CD /D %%G
SET CURR_SIZE=0
FOR /R %%Y IN (*) DO (SET /A CURR_SIZE=!CURR_SIZE!+%%~zY)
CD /D ..


IF /I !CHILD_LOOPS! gtr %IGNORE_NUM% ( 
SET /A CHILD_DELETES=!CHILD_DELETES!+1
SET /A CHILD_DELETE_AMOUNT=!CHILD_DELETE_AMOUNT!+!CURR_SIZE!
ECHO !time! Deleting %%G %%~tG !CURR_SIZE! >> "%LOG_FILE%
RD /S /Q %ROOT_DIR%\%%H\%%G
)ELSE (
SET /A CHILD_IGNORES=!CHILD_IGNORES!+1
SET /A CHILD_IGNORE_AMOUNT=!CHILD_IGNORE_AMOUNT!+!CURR_SIZE!
ECHO !time! Ignoring %%G %%~tG !CURR_SIZE! >> "%LOG_FILE%"
)
SET /A CHILD_LOOPS=!CHILD_LOOPS!+1
)

ECHO !time! ---------------------------------------------------------------- >> "%LOG_FILE%"

SET /A CONVERTED_DELETE_AMOUNT=!CHILD_DELETE_AMOUNT!/1048576
SET /A CONVERTED_IGNORE_AMOUNT=!CHILD_IGNORE_AMOUNT!/1048576

ECHO !time! !CHILD_DELETES! of !CHILD_LOOPS! folders deleted >> "%LOG_FILE%"
ECHO !time! !CONVERTED_DELETE_AMOUNT!MB deleted !CONVERTED_IGNORE_AMOUNT!MB ignored >> "%LOG_FILE%"
ECHO !time! >> "%Log_FILE%"

SET /A MOTHER_LOOPS=!MOTHER_LOOPS!+1
SET /A MOTHER_DELETES=!MOTHER_DELETES!+!CHILD_DELETES!
SET /A MOTHER_IGNORES=!MOTHER_IGNORES!+!CHILD_IGNORES!
SET /A MOTHER_DELETE_AMOUNT=!MOTHER_DELETE_AMOUNT!+!CHILD_DELETE_AMOUNT!
SET /A MOTHER_IGNORE_AMOUNT=!MOTHER_IGNORE_AMOUNT!+!CHILD_IGNORE_AMOUNT!

)

SET /A CONVERTED_DELETE_AMOUNT=!MOTHER_DELETE_AMOUNT!/1048576
SET /A CONVERTED_IGNORE_AMOUNT=!MOTHER_IGNORE_AMOUNT!/1048576
ECHO %time% Total deleted folders: %MOTHER_DELETES% >> "%LOG_FILE%"
ECHO %time% Total ignored folders: %MOTHER_IGNORES% >> "%LOG_FILE%"
ECHO %time% Total deleted data: ^~%CONVERTED_DELETE_AMOUNT%MB >> "%LOG_FILE%"
ECHO %time% Total ignored data: ^~%CONVERTED_IGNORE_AMOUNT%MB >> "%LOG_FILE%"
ECHO %time% In %MOTHER_LOOPS% eSpaces >> "%LOG_FILE%"

ECHO.

ECHO Log path: 
ECHO %LOG_FILE%

ECHO.

ECHO Summary:
ECHO deleted folders: %MOTHER_DELETES%
ECHO ignored folders: %MOTHER_IGNORES%
ECHO deleted data: ^~%CONVERTED_DELETE_AMOUNT%MB
ECHO ignored data: ^~%CONVERTED_IGNORE_AMOUNT%MB
ECHO In a total of %MOTHER_LOOPS% eSpaces


goto:END


:BAD_PARAMETERS
ECHO.
ECHO ERROR: Invalid input parameters
goto:HELP

:BAD_PATH
ECHO.
ECHO ERROR: Invalid folder path
goto:HELP

:BAD_IGNORE_NUM
ECHO.
ECHO ERROR: Invalid keepnumber
goto:HELP


:HELP
ECHO.
ECHO -------------usage-------------
ECHO ASPNETTEMPFILESCLEANUP ^ [^]
ECHO.
ECHO Description:
ECHO Delete old temporary Asp.Net folders. BE SURE TO INTRODUCE THE CORRECT TEMPORARY ASP.NET FILES PATH, BECAUSE OLD FOLDERS AND SUBFOLDERS WILL BE DELETED WITHIN THAT PATH.
ECHO.
ECHO Parameter List:
ECHO ^
ECHO Path to the Temporary ASP.NET Folders
ECHO Default folder is %windir%\Microsoft.NET\Framework^\^\Temporary ASP.NET Files
ECHO.
ECHO ^
ECHO Number of recent folders to keep, besides the newest
ECHO Default value is 0 (zero)
ECHO.
ECHO Examples:
ECHO ASPTempFilesCleanup "E:\ASP.Net Temporary Folder\"
ECHO ASPTempFilesCleanup "E:\ASP.Net Temporary Folder\" 1
ECHO.
ECHO Log:
ECHO Dumped into ^\ASPNETTempFilesCleanup.log



:END

Check port status for bulk server's.

Check port status for bulk server's.


ECHO #

for /f %%C in (ServerName.txt) do (

ECHO %%C >>port_report.txt


portQry.exe -n %%C -o 135,136,137,138,139,445 -p both | find "LISTENING" >>port_report.txt

)

ECHO #

How to check physical CPU count and server status (PHYSICAL or VIRTUAL) for bulk server's.

How to check physical CPU count and server status (PHYSICAL or VIRTUAL) for bulk server's ?

Solution: Power Shell Script.

Create a file servername.txt in local script path having server's name.


function Get-CPUs {
    param ($server, $username)
    if ($username)
    {
        $processors = get-wmiobject -computername $server -credential $username win32_processor
    }
    else
    {
        $processors = get-wmiobject -computername $server win32_processor
    }
    if (@($processors)[0].NumberOfCores)
    {
        $cores = @($processors).count * @($processors)[0].NumberOfCores
    }
    else
    {
        $cores = @($processors).count
    }
    $sockets = @(@($processors) |
    % {$_.SocketDesignation} |
    select-object -unique).count;

$objWMI = $NULL
$bln = $NULL
$objWMI = Get-WmiObject -computername $server Win32_ComputerSystem


Write-Host –NoNewLine $server, CORE, $cores, SOCKET, $sockets, $objWMI.manufacturer,  $objWMI.model  -ForegroundColor "YELLOW"

   
Write-host ("");
}

# Get server list
$servers = Get-Content "servername.txt";
$datetime = Get-Date -Format "yyyyMMddHHmmss";

foreach($server in $servers)
{
Get-CPUs $server
}