Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to map drives in powershell

Posted on 2012-12-27
9
Medium Priority
?
1,618 Views
Last Modified: 2012-12-27
Hello what is the equivalent of the following:

net use Z: \\computername\c$ /u:computername\username 'password'

in powershell ?

Thanks,
0
Comment
Question by:namerg
[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
  • 5
  • 4
9 Comments
 
LVL 29

Assisted Solution

by:becraig
becraig earned 2000 total points
ID: 38725015
new-psdrive -name Z -psprovider Filesystem -Root "\\server\folder"

Details on the command:

http://technet.microsoft.com/en-us/library/hh849829.aspx
0
 

Author Comment

by:namerg
ID: 38725029
Hmm, not quite, I want to map toward C$

I get the following error:

new-psdrive : Drive root "\\computername\c$" does not exist or it is not a folder.
At line:1 char:1
+ new-psdrive -name Z -psprovider Filesystem -Root "\\computername\c$"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (Z:PSDriveInfo) [New-PSDrive], IOException
    + FullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand

Thanks,
0
 
LVL 29

Expert Comment

by:becraig
ID: 38725113
You may want to look at the "credential" section of the link in my comment since you want to map to an admin share.
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:namerg
ID: 38725183
Ok, got it. But how do I avoid the window pop up for the password  ?
0
 
LVL 29

Expert Comment

by:becraig
ID: 38725222
you can specify the persist option to keep the drive mapped
0
 

Author Comment

by:namerg
ID: 38725229
I am able to map it but how do i pass the password via powershell script without having that pop up. And, I have to remove the mapped drive because of security. Thanks.
0
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 38725252
You can pass the password into the script using pscredential

-Credential<PSCredential>

Specifies a user account that has permission to perform this action. The default is the current user.
Type a user name, such as "User01" or "Domain01\User01". Or, enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
Beginning in Windows PowerShell 3.0, when the value of the Root parameter is a UNC path, you can use credentials to create file system drives. This parameter is not supported by all Windows PowerShell providers.

You can do some research on that to determine how to proceed.
0
 

Author Comment

by:namerg
ID: 38725275
Got it. Thank You very much.
0
 
LVL 29

Expert Comment

by:becraig
ID: 38725278
Np glad to be of some help
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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