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
- 40 Getting started
- 24 Read before posting
- 8 Meet and greet
- 219 General
- 59 News and announcements
- Swag
- 1 Roadmap updates
- 68 Resources
- 9 Knowledge Base
- 13 Webinars
- 1 Shared Script Library
- 2 Blog
- 15 Pro Tips
- 26 Got an idea?
- 1 Atera Academy
- 1 ActionAI
- 1 Copilot
- 123 Remote Monitoring and Management
- 77 Remote Monitoring
- 23 Patch Management
- 98 Professional Services Automation
- 61 Helpdesk
- 17 Billing
- 18 Reporting
- 33 Integrations & add-ons
- 19 Integrations
- 10 Add-ons
- 99 Scripting and automations
- 58 Scripts
- 29 Automations