[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Drive Mappings with powershell

Posted on 2013-05-22
6
Medium Priority
?
651 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 2000 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This Micro Tutorial demonstrates how to create custom reports and the secrets of determine the metrics and dimensions for your data that works best with your needs.
This Micro Tutorial demonstrates in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

873 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