Permanently mapping network drive for all users?
Has anyone figured out a PS script (or bat etc) that would permanently map a password protected network drive for all users of a remote workstation?
I've tried a couple of approaches - New-SMBMapping
, New-SmbGlobalMapping
, New-PSDrive
but I can't figure it out. At best I was able to map a network share, but it was gone after reboot.
Comments
-
@PrzemekJ To map a network drive with PowerShell, you can use the
New-PSDrive
cmdlet. However, the drive mapping created withNew-PSDrive
only lasts for the duration of the PowerShell session. If you want the mapping to persist across reboots and for all users, you would traditionally use thenet use
command with the/persistent:yes
option, but this will only apply to the currently logged-in user, not all users.To make a persistent network drive mapping that applies to all remote workstation users, you would need to create a script and ensure it runs at startup for each user. This would require administrative privileges on the target workstation.
However, storing passwords in a script is not considered a good security practice as it can lead to potential security issues. Consider using network drives that don't require individual user passwords or find a secure credential storage and retrieval method if possible.
Here is a general example of what the PowerShell script might look like:
$Username = "username"
$Password = ConvertTo-SecureString "password" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($Username, $Password)
$DriveLetter = "Z:"
$NetworkPath = "\\server\share"
$Persist = $true
New-PSDrive -Name $DriveLetter -PSProvider FileSystem -Root $NetworkPath -Persist $Persist -Credential $Credential
In this example, replace
"username"
and"password"
with the network drive's username and password. Replace"Z:"
with the drive letter, you want to assign to the network drive and replace"\\server\share"
with the path to the network drive.To run this script at startup for each user, you must place it in the shared startup folder. The standard startup folder for all users in Windows is typically located at
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
.But remember, the method described above isn't secure because the password isn't encrypted or secured. It's generally not recommended to store passwords in plain text. Instead, you should look for ways to securely store the credentials or use a system that doesn't require per-user network drive authentication.
1 -
Thanks @tanderson !
1
Topics
- All Topics
- 41 Getting started
- 25 Read before posting
- 8 Meet and greet
- 238 General
- 64 News and announcements
- 1 Swag
- 1 Roadmap updates
- 79 Resources
- 12 Knowledge Base
- 16 Webinars
- 1 Shared Script Library
- 2 Blog
- 19 Pro Tips
- 27 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 140 Remote Monitoring and Management
- 84 Remote Monitoring
- 27 Patch Management
- 106 Professional Services Automation
- 65 Helpdesk
- 17 Billing
- 21 Reporting
- 37 Integrations & add-ons
- 20 Integrations
- 10 Add-ons
- 103 Scripting and automations
- 61 Scripts
- 30 Automations