Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I create a new shared drive with the provided credentials on the computer that is running the script?

Is there a PowerShell cmdlet that does that?

share|improve this question

closed as not a real question by user48838, mailq, MDMarra, Ben Pilbrow, Shane Madden Aug 29 '11 at 4:24

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
I don't understand what you mean by shared driver. Do you mean shared drive? –  Ben Pilbrow Aug 28 '11 at 11:52
    
@Ben: Yes, shared drive. Sorry it's a typo... –  the_drow Aug 28 '11 at 14:09
    
And now: Do you mean to create a public share or how to map a public share to a drive letter? –  mailq Aug 28 '11 at 15:21
    
Sorry :/ I am asking how to map a public share to a drive letter. –  the_drow Aug 29 '11 at 7:00
    
@mailq Why isn't this a real question? –  the_drow Aug 30 '11 at 7:47

2 Answers 2

This powershell function should work:

Function NEW-SHARE ($Foldername, $Sharename) { 
   # Test for existence of folder, if not there then create it 
   # 
   IF (!(TEST-PATH $Foldername)) { 
       NEW-ITEM $Foldername -type Directory } 
   # Create Share but check to make sure it isn’t already there 
   # 
   If (!(GET-WMIOBJECT Win32_Share -filter “name=$Sharename”) { 
       $Shares.Create($Foldername,$Sharename,0)} 
}

The following article on technet provides more information:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/16/how-to-use-powershell-to-create-shared-folders-in-windows-7.aspx

share|improve this answer

Just use "net use" inside your powershell scripts:

new use z: \\server\share /user:domain\username password

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.