set SHARE=\\fileserver\dept set DRIVE=M: net use %DRIVE% %SHARE% /persistent:yes
for a deep dive into the complex world of mapping drives for Windows Services. Are you looking to automate this for multiple users via a script, or just for your own local machine Guide: How to Map a Network Drive in Windows - NinjaOne cmd map network drive better
Registry setting to allow linked connections (set carefully; requires admin): cmd map network drive better