Create a start-up script for drive and printer mapping in Intune as Win32 app.

Step 1. Create the .cmd script

Copy the script below and fill in your own Driveletter, Servername + Sharename and Printers between the % signs

@Echo Off

REM WAIT FOR DEVICE TO FULLY BE ONLINE AND CONNECTED TO A VPN IF NEED BE
timeout /T 130 /NOBREAK > nul
Net use %driveletter% \\%servername%\%sharename%

REM DO A QUERY ON REGISTRY FOR IF PRINTER ALREADY EXISTS AND SKIP ADDING PRINTER IF IT DOES
reg query "HKCU\Printers\Connections\,,%servername%,$printername%" /ve
if %ERRORLEVEL% EQU 0 goto bye

REM Add printer
rundll32 printui.dll,PrintUIEntry /in /q /n"\\%servername%,$printername%"

REM Set printer as default
rundll32 printui.dll,PrintUIEntry /y /n"\\%servername%,$printername%" /q

:bye
Exit

Step 2. Create 2nd script to get the script in the start up folder of the users
Copy the script below and fill in your own name of the first script you created between the % signs

timeout /T 30 /NOBREAK > nul
xcopy %nameoffirstscript%.bat "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp" /y

Step 3. convert the scripts to IntuneWin files for Intune (Win32 App)
Download the Microsoft Win32 content prep tool on github:
Win32Tool


Go to the folder where you have saved the IntuneWinAppUtil.exe tool
cd %LocationWhereYouSavedTheIntuneWinAppUtil.exe%

Open IntuneWinAppUtil.exe via CMD and fill in the following details:
Source folder: (where you have saved the scripts)
Setup file: (name of the 2nd script)
Output folder location: (where you would like to have the .intunewin file

Step 4. Upload .intunewin file to EndPoint Manager (Intune)
Go to EndpointManager
Apps -> Windows Apps and click on “Add”

Add the file as new Win32 Application in Intune

Select the .Intunewin file you have created

Fill in the name, description and publisher

Install command: %name of second script%

Uninstall command: Del “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\%nameof1stscript%” /y

Install behavior: System

Device Restart behavior: No specific action

Select the appropriate requirements

Select the option “manually configure detection rules”
Rule type: File
Path: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
File or folder: %nameoffirstscript%
Detection method: File or folder exists


Finish the app creation by assigning it to the users or devices that you want it to receive.
Voila!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s