Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to map drives in powershell

Posted on 2012-12-27
9
Medium Priority
?
1,710 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 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Loops Section Overview
Screencast - Getting to Know the Pipeline

916 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