2

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?

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

2

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.