Solved

How to map drives in powershell

Posted on 2012-12-27
9
1,314 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
  • 5
  • 4
9 Comments
 
LVL 28

Assisted Solution

by:becraig
becraig earned 500 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 28

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
 

Author Comment

by:namerg
ID: 38725183
Ok, got it. But how do I avoid the window pop up for the password  ?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

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 28

Accepted Solution

by:
becraig earned 500 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 28

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

12 Experts available now in Live!

Get 1:1 Help Now