Worklet: Network Drive Mount Windows

  • 18 October 2019
  • 3 replies
  • 40 views

Userlevel 7

Mounts a network drive to a drive letter.


Evaluation code:

None


Remediation code:


#REQUIRES -Version 2.0
<#
.SYNOPSIS
This script allows an admin to mount a new network drive.
.DESCRIPTION
This script mounts a network drive on clients machines. Script will not
execute propery if ran in administrator mode. The new drive will be persistant
across reboots.
This is an example script that has been tested to work on Win10 and Win7.
This script may not work on all systems. Modify to fit your needs
.NOTES
File Name :NetworkDriveMount.ps1
Author :Automox
Prerequisite :PowerShell V2 over win7 and upper
#>
#Handle Exit Codes:
trap { $host.ui.WriteErrorLine($_.Exception); exit 90 }

function NetworkDriveMount {
#############Change the settings in this block#######################
$Name="T" #What letter to mount the drive as.
$PSProvider = "FileSystem" # optionally set to Registry to map to reg key
$Path= "\\Readyshare\T_Drive" #where the drive is located
#####################################################################

New-PSDrive -Name $Name -PSProvider FileSystem -Root $Path -Persist
}

NetworkDriveMount

3 replies

Hi Nic, I’m trying this as a Worklet for my company but the issue seems to be that when the worklet runs it runs as the root user and therefore the script doesn’t know which credentials to use for mapping the drive. How might I go about running this worklet as the current logged in user or something like that? Any help is appreciated.

Userlevel 7

Yeah the script runs as System, so it doesn’t know who to map the drive as. I’ll see about creating a version of this that runs as the user, using the scheduled task trick, to map the drive from them rather than the System user.

Yeah the script runs as System, so it doesn’t know who to map the drive as. I’ll see about creating a version of this that runs as the user, using the scheduled task trick, to map the drive from them rather than the System user.

Has there been a solution found for this?

Reply