Skip to main content

Worklet: Network Drive Mount Windows

  • October 18, 2019
  • 3 replies
  • 245 views

Nic-Automox

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

  • 0 replies
  • July 7, 2020

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.


Nic-Automox
  • Author
  • Former Automox Employee
  • 832 replies
  • July 7, 2020

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.


TJ_Coppola
Forum|alt.badge.img
  • Pro
  • 32 replies
  • December 1, 2021
Nic wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings