Solved

How to map drives in powershell

Posted on 2012-12-27
9
1,383 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 29

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 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
Are your AD admin tools letting you down?

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 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 29

Expert Comment

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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Set OWA language and time zone in Exchange for individuals, all users or per database.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

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