21/03/2012

Remove Device Inativos após P2V

Customização de server P2V, após a virtualização tem um script que ajuda a remover o devices inativos do servidor, processo este que atualmente é feito manualmente, e muito demorado conforme abaixo.

1. comando set devmgr_show_nonpresent_devices=1
2. comando start devmgmt.msc
3. Habilitar opção Hidden devices

Segue Script abaixo onde foi realizado teste em um servidor de PV2 que neste tinha vários devices inativos após a execução do bat este removeu mais de 98% dos devices foi reiniciado o servidor e não foi identificado problemas neste, observando que antes de executar o script via arquivo bat é necessário remover o software que não serão utilizados.
Obs.; Salve o arquivo remove.txt com a extensão remove.bat, baixe e copie e executável devcon.exe para caminho c:\windows\system32 do servidor P2V
O script tem a função de ajudar no processo, lembrando que ainda existem pontos que devem ser feitos manualmente.

Script


@ECHO OFF
:: Check DOS/Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax

:: Localize variables
SETLOCAL

:: Check command line arguments
IF NOT "%~1"=="" IF /I NOT "%~1"=="/D" IF /I NOT "%~1"=="/Y" GOTO Syntax

:: Check if debug mode is requested
IF /I NOT "%Debug%"=="ECHO" SET Debug=
ECHO.%* | FIND /I "/D" >NUL && SET Debug=ECHO

:: Check if confirmation is required
SET Confirmed=N
ECHO.%* | FIND /I "/Y" >NUL && SET Confirmed=Y

:: Check if DEVCON.EXE is available and if not, prompt for download
SET DevconAvailable=
SET Download=
DEVCON.EXE /? >NUL 2>&1
IF ERRORLEVEL 1 (
SET DevconAvailable=No
ECHO This batch file requires Microsoft's DEVCON untility.
SET /P Download=Do you want to download it now? [y/N]
)

:: Start download if requested
IF /I "%Download%"=="Y" (
START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
ECHO.
ECHO Install the downloaded file and make sure DEVCON.EXE is in the PATH.
ECHO Then try again.
)

:: Abort if DEVCON.EXE is not available yet
IF "%DevconAvailable%"=="No" GOTO End

:: Ask for confirmation, unless overruled by command line switch
IF NOT "%Confirmed%"=="Y" (
ECHO You are about to remove all inactive PnP devices from this computer.
SET /P Confirmed=Are you sure you want to continue? [yN]
)
IF /I NOT "%Confirmed%"=="Y" GOTO Syntax

:: Save a list of all active devices in a temporary file
DEVCON Find * | FIND /I /V "matching device(s)" > "%Temp%\DevconFind.txt"
IF NOT EXIST "%Temp%\DevconFind.txt" GOTO Syntax

:: List all devices, both hidden/inactive and active ones, and remove
:: all devices that are not listed as active in the temporary file
FOR /F "tokens=1 delims=: " %%A IN ('DEVCON FindAll * ^| FIND /I /V "matching device(s)"') DO (
TYPE "%Temp%\DevconFind.txt" | FIND "%%~A" >NUL
IF ERRORLEVEL 1 %Debug% DEVCON Remove "@%%~A"
)

:: Remove the temporary file
DEL "%Temp%\DevconFind.txt"

:: Done
ENDLOCAL
GOTO:EOF

:Syntax
ECHO.
ECHO RmHidDev.bat, Version 1.00 for Windows 2000 / XP
ECHO Use DEVCON to remove all hidden/inactive PnP devices.
ECHO.
ECHO Usage: RMHIDDEV [ /D ] [ /Y ]
ECHO.
ECHO Where: /D Will only ECHO the removal commands instead of executing them
ECHO /Y Will remove devices without confirmation
ECHO.
ECHO Notes: [1] This batch file requires Microsoft's DEVCON.EXE, available at
ECHO http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
ECHO You will be prompted for download if it isn't found.
ECHO [2] This batch file was developed with "ghost devices" on Ghost images
ECHO in mind. It has been tested on Windows XP Ghost images only.
ECHO I cannot guarantee flawless operation on any other PC.
ECHO Use this batch file entirely at your own risk. Make sure you have
ECHO a recent full backup available in case something might go wrong.
ECHO And remember to test, test, test and test before using it in a
ECHO production environment.
ECHO.
IF "%OS%"=="Windows_NT" ENDLOCAL

Fonte.: Script http://www.robvanderwoude.com

Nenhum comentário:

 
Pesquisa personalizada