Solved

Drive Mappings with powershell

Posted on 2013-05-22
6
643 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This Micro Tutorial will demonstrate how to use comments in Google Docs. You will learn how to create, edit, and delete a comment.
This Micro Tutorial will demonstrate common damaging and frequent mistakes I see in most analytic audits. Most of them are campaign tagging mistakes, so this video will break it down into simple steps.

772 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