Solved

Drive Mappings with powershell

Posted on 2013-05-22
6
640 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SolarWind and DNS Server 12 36
ACTIVE DIRECTORY 3 27
ACTIVE DIRECTORY 4 23
lync 2013 7 31
This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
This Micro Tutorial demonstrates the importance of annotations in Google Analytics and how they should be used to document changes made to a site, Google updates (Ex: Panda & Penguin), marketing campaigns, and any other events that might have contriā€¦

708 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

15 Experts available now in Live!

Get 1:1 Help Now