Solved

Drive Mappings with powershell

Posted on 2013-05-22
6
642 Views
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
0
Comment
Question by:FalconTwo
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:BT15
ID: 39189039
I am pretty sure the code is

$net.removenetworkdrive("y:")
0
 
LVL 7

Accepted Solution

by:
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.RemoveNetworkDrive("y:")
}
$net.MapNetworkDrive("Y:", "\\BWKPW21\GDrive")

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

Open in new window

0
 
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
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

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

Author Closing Comment

by:FalconTwo
ID: 39189078
WOW works like a charm thanks
0
 
LVL 7

Expert Comment

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

you are welcome
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This Micro Tutorial will demonstrate importing calendar invites from events such as webinars into your Google Calendar.
This Micro Tutorial demonstrates in Google Analytics how to create a custom report that shows you traffic over time using the month of year dimensions. There are also instructions on how to fix Google's odd month of year formatting, which Microsoft …

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now