Solved

Drive Mappings with powershell

Posted on 2013-05-22
6
647 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
[X]
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
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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

728 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