Drive Mappings with powershell

Posted on 2013-05-22
Last Modified: 2014-11-12
Hello Gurus

I have a windows 2003 domain and I would like to use a PS1 file to map use drives.

Here's what I have so far

# PowerShell Logon Script Example
$net = $(New-Object -ComObject WScript.Network)
$net.MapNetworkDrive("Y:", "\\BWKPW21\GDrive")
$net.MapNetworkDrive("Z:", "\\BWKPW21\RXS")

I would like to remove the drives first then mapped them like we did in the batch logon script.
Thanks for your help. Any additional input will be much appriciated
Question by:FalconTwo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 39189039
I am pretty sure the code is


Accepted Solution

BT15 earned 500 total points
ID: 39189053
this checks for the drives you listed above. if they are already mapped, it removes them.

then it maps the drives

$net = $(New-Object -ComObject WScript.Network)

if ($net.EnumNetworkDrives() | ? {$_ -eq "y:"}){
$net.MapNetworkDrive("Y:", "\\BWKPW21\GDrive")

if ($net.EnumNetworkDrives() | ? {$_ -eq "z:"}){
$net.MapNetworkDrive("Z:", "\\BWKPW21\RXS")

Open in new window

LVL 18

Expert Comment

by:Sarang Tinguria
ID: 39189056
Why powershell ..?
Net use is simple

net use I: /delete
net use J: /delete
net use K: /delete
above is to delete existing drives

net use {drive letter:} \\{machine name} to map new  drives
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.


Author Comment

ID: 39189070
LOL Hi Sarang, Powershell or vb script  is the way to go now. A whole new world now exist out there

Author Closing Comment

ID: 39189078
WOW works like a charm thanks

Expert Comment

ID: 39189257
because with powershell you can do anything :)

you are welcome

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This Micro Tutorial will demonstrate importing calendar invites from events such as webinars into your Google Calendar.
In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question