Uncategorized · June 19, 2021 0

Printer migration script

Hi powermators,

in enterprise environment it may get complicated when Printers are getting upgraded and new Print-Servers are placed. From administrator point of view, installing a new printer-server is not that hard, but changing the printers at the clients side might be an issue; as you don’t have an eye what is configured under each profile!

today I am showing you a windows script that I have modified and adapted in a printers migration project. Basically it was intended to do the following

§ it reads in the registry for local profiles (some profiles are filtered out)

§ Get all network printers (local ones will be ignored)

$ generate a list of them under C:\temp\printers.txt so that the output look like this

$ swapping the old printer server name with new one.

I used SCCM to deploy the script on the clients but you can also use other tools available in your environment.

Below is the script, feel free to modify and use. Notice that you need to save it as .bat file

REM --------Specify users to filter out
IF "!userPath!" == "Administrator" SET isUser=false
IF "!userPath!" == "defaultuser0" SET isUser=false
IF "!userPath!" == "Public" SET isUser=false
IF "!isUser!" == "true" (
IF EXIST "C:\users!userPath!\" (
REM --------Make sure the key actually exists
REG QUERY "HKU!line:~76!" >nul 2>&1
IF !ERRORLEVEL! EQU 0 (
ECHO Processing printers for !userPath!
ECHO !userPath!: >> !textFile!
REM -------Get Default Printer
for /f "tokens=3 delims=, " %%a in ('reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device ^| find /i "Device"') do (
set Device=%%a

REM -------Get all network printers
FOR /F "tokens=*" %%F IN ('REG QUERY "HKU!line:~76!\Printers\Connections" 2^>nul') DO (

REM ------Format the output to only contain the printer name. Then print it to the text file.
SET newLine=%%F
SET output=!newLine:*Connections=!

FOR /f "tokens=1-4 delims=," %%a IN ("!newLine:*Connections=!") DO (

REM ------if the printer alias isthe old server then remove it and add it with the new alias
REM IF %%a== at-npf1-m003 (rundll32 printui.dll,PrintUIEntry /dn /n !output:,=!
REM rundll32 printui.dll,PrintUIEntry /in /n\printserver\%%b
REM IF %%b==%Device:~15,30% (rundll32 printui.dll,PrintUIEntry /y /n\printserver\%%b
REM echo passt for %%b)
REM
)

)

ECHO !output:,=\! >> !textFile!
)
ECHO.>>!textFile!
)
)
)
)

)

Close Bitnami banner
Bitnami