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?

  • 1
    I don't understand what you mean by shared driver. Do you mean shared drive? 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

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”) { 

The following article on technet provides more information:



Just use "net use" inside your powershell scripts:

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

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