Question

Managing Mapped Drives

  • 1 December 2021
  • 2 replies
  • 66 views

Considering the shift to remote work, managing mapped drives through group policy isn’t as effective as it would be with the majority of users being on premises. 

I would like to use shift to using Automox worklets to manage mapped network drives, but when I test using PowerShell commands like “New-PSDrive” it runs as the administrator and the drives don’t appear for the end user. 

My current solution is to drop a .cmd file into the startup folder, but this is inelegant. Is there a better way to do this?


2 replies

Looks like this was covered in a previous post, but a solution wasn’t found.

Userlevel 4

Could leverage scheduled task running in the user context. 

 

copy-item script.ps1 C:\windows\temp\script.ps1

$TaskStartTime = (Get-Date)
$SchedService = New-Object -ComObject Schedule.Service
$SchedService.Connect()
$Task = $SchedService.NewTask(0)
$Task.RegistrationInfo.Description = 'Description'
$Task.Settings.Enabled = $TaskSchd
$Task.Settings.AllowDemandStart = $true
$Task.Settings.WakeToRun = $true
$trigger = $Task.triggers.Create(1) # https://docs.microsoft.com/en-us/windows/win32/taskschd/triggercollection-create
$trigger.StartBoundary = $TaskStartTime.ToString("yyyy-MM-dd'T'HH:mm:ss")
$trigger.Enabled = $true
$action = $Task.Actions.Create(0)
$action.Path = "c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$action.Arguments = '-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "C:\windows\temp\script.ps1"'
$taskFolder = $SchedService.GetFolder('\')
$taskFolder.RegisterTaskDefinition("Task Name", $Task , 6, 'Users', $null, 4) | out-null

Reply