In every modern management project where we use Azure AD Join instead of traditional domain join, there are always some network drives that needs to be mapped for the end users. Not very modern I know but there is a real world out there as well. When we use a modern client using sleep or hibernate is the new way to work. Running a script at logon isn’t enough we need to be more flexible. There are a great number of great logon script samples out there so I will not go down that way. Instead adding a trigger to a scheduled task to run when we connect to a network with a specific name, is a useful addition which makes the end-user experience much better.
Here is a short demo on how to map drives when connecting to corporate network.
But wait! No blue PowerShell splash screen was in the video. I use PSRun.exe that my colleague Johan Schrewelius has written which you can find here: https://onevinn.schrewelius.it/Apps01.html. PSRun suppresses the PowerShell splash screen and passes all commands that you execute PSRun with directly to PowerShell.
The action we use in the schedule task looks like below. The arguments line can hardly be read in the screenshot but it looks like this: -executionpolicy Bypass -file “C:\Program Files\ConnectDrives\ConnectDrives.ps1”
Our Schedule Task have two triggers, one to run at logon and one custom that runs when connected to a network with a specific name. It looks like this:
The custom event filter contains the network name for which we will use to trigger the script when connected to.
I wrote a simple sample script to import the schedule task and copy the simple script I used to map the drives to C:\Program Files\ConnectDrives. It also writes to the registry so there is a registry key and value. Which can be used as a detection method when deploying it using Win32App on our modern clients.
Privacy & Cookies Policy
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.