Map network drive to computer without user sign in

IsacICT 1 Reputation point
2021-11-15T12:26:39.567+00:00

Hello all,

I need to map a cloud drive to the file server. It works when I manually map it but it needs to be available after the server restarts without requiring user sign in. I created a PowerShell script and works when I run it with a regular user and maps the drive.

The issue start when I put the script under startup scripts on local GPO, computer policy > Windows Settings > Scripts > startup (since no user logins to file server). It doesn't map the drive. SYSTEM account has full access to the script location.

My Script is below, I tried many different parameters like this to run the script -Noninteractive -ExecutionPolicy UnRestricted –NoProfile -file


$cred = Import-CliXml -Path "C:\scripts\my-Cloud-Drive-Map.xml"

New-PSDrive -Name "L" -Root "\XXX.file.core.windows.net\yyyy" -Persist -PSProvider "FileSystem" -Credential $cred

Net Use


I also created a batch file to run this script;


PowerShell -Command "Set-ExecutionPolicy Unrestricted -Scope LocalMachine" >> "C:\scripts\StartupLog.txt" 2>&1

Powershell -Noninteractive -ExecutionPolicy Unrestricted -file C:\scripts\my-Cloud-Drive-Map.ps1 >> "C:\scripts\StartupLog.txt" 2>&1


I'm currently testing with Windows 10 Pro but my fileserver is Server 2012 Standard R2

Please advise.

Thank you.

Isac

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,423 questions
{count} votes

5 answers

Sort by: Most helpful
  1. MotoX80 32,331 Reputation points
    2021-11-15T16:00:27.943+00:00

    A mapped drive is tied to a user's session. You and a co-worker can both RDP to a server. You can map the L: drive to \server1\share1, and your co-worker can map the L: drive to \xxxxxxx\yyyyyy.

    How do you intend to use this mapped drive? From a scheduled task? From a Windows service? What account will that process execute as?

    0 comments No comments

  2. Rich Matheisen 45,261 Reputation points
    2021-11-15T16:02:20.717+00:00

    From the "Description" of the New-PSDrive cmdlet's "help":

    When your command is scoped locally, no dot-sourcing, the Persist parameter doesn't persist the creation of a PSDrive beyond the scope in which the command is running. If you're running New-PSDrive inside a script, and you want the drive to persist indefinitely, you must dot-source the script. For best results, to force a new drive to persist indefinitely, add the Scope parameter to your command, and set its value to Global. For more information about dot-sourcing,

    0 comments No comments

  3. IsacICT 1 Reputation point
    2021-11-16T10:57:17.487+00:00

    Unfortunately, no matter what I tried, it only maps for the SYSTEM account and the admin account I created the policy (maybe for also other admins).

    I need this mapped drive to be accessed on fileserver so domain users don't log in to the file server, they only access shares. This is the reason it needs to be available for everybody.

    Thanks.


  4. RapidCloudIT 0 Reputation points
    2024-05-07T16:58:20.5633333+00:00

    Did you ever find a solution to this? I have the exact same problem.

    • I'm trying to setup a scanner to scan to a Google Drive folder.
    • The scanner itself doesn't have any cloud apps built into it, so I have to scan to a shared network drive.
    • So, I "share" one of the Google Drive mapped drive folders.
    • This is fine until the computer restarts. When the computer restarts, mapped drives are gone until a user logs in, AND shared drives do not persist through reboot.
    • This means after a weekend of patching, and the computer reboots, the connection from the scanner to the shared drive breaks.
    • Google Drive does automatically remap all the drives, but not until a user logs in.
    • So, I can't run a script at STARTUP after a reboot to share a drive because there is no mapped drive to share. Therefore, I have to schedule the share task to run after a user logs in. This is not ideal.

    Right now, I seem to have two choices:

    • Live with the crappiest solution, which is that the scanner will only be able to scan to the Google drive after a user logs into the machine that was restarted (User logs in, Google Drive maps the drive, the task scheduler shares the mapped drive, now I can scan to the Google drive)
    • Switch to using an actual network path on a server somewhere, instead of a Google drive.

  5. Rich Matheisen 45,261 Reputation points
    2024-05-08T01:41:01.3033333+00:00

    Why don't you just use the "NET USE . . ." and the "/PERSISTENT:YES" parameter to create the mapping?