Share via


new-smbShare error - filename, directory anme .... syntax is incorrect. server 2012 R2

Question

Tuesday, September 4, 2018 6:06 PM

i need to create a new shared folder on a remote server and then change the share permission for everybody to FullAccess. i cant figure it out after a whole day of fooling around.

i am able to use the new-item  cmdlet to create the folder. 

the new-smbshare is giving me the error below.

$Username  = Test

 ## Name and Path for Personal drive folder
    $ComputerName = "contoso"
    $DriveLetter = "H"
    $Path = "Users"
    New-Item -Path \$ComputerName\DriveLetter$\Path\Username -type directory -Force 
    
    New-SmbShare -Name $Username  -Path \$ComputerName\DriveLetter$\Path\Username  -ReadAccess domain\Everyone

Here is the error

New-SmbShare : The filename, directory name, or volume label syntax is incorrect. 
At line:5 char:5
+     New-SmbShare -Name $Username  -Path \$ComputerName\DriveLetter$ ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare 
   ) [New-SmbShare], CimException
    + FullyQualifiedErrorId : Windows System Error 123,New-SmbShare

All replies (4)

Wednesday, September 5, 2018 7:10 AM

Hi,

Thanks for your question.

I observed that a small error in above powershell command as below, one more $ was added. Other parameters are right. 

In addition, would you like to change the share permission for everyone to full access? You need to change "ReadAccess" to "FullAccess" in the command.

Hope this helps, if you have any question or concern, please feel free to let me know.

Best regards,

Michael 

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Wednesday, September 5, 2018 9:20 AM

Hi,

Sorry, I made a mistake. The command was right, but it seems to be infeasible. We cannot create a share on a mapped drive or on a remote system with the SMB tools. Please refer to the thread discussed  the similar situation, 

https://social.microsoft.com/Forums/en-US/bd9436c5-01f6-4491-852c-2d976a68ba31/powershell-newsmbshare-cmdlet-not-working-on-remote-server?forum=Offtopic

Best regards,

Michael

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Thursday, September 6, 2018 2:09 AM

Hi,

I saw your Email reply, I think it is a very helpful answer. Was your issue resolved now? Shall I post your answer?

Please let us know if you need further assistance.

Best regards,

Michael

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Thursday, September 13, 2018 6:58 AM

Hi,

I'll post your answer, it is correct, and it would be helpful to others who encounters a similar issue. Your contribution and effort are very appreciated.

this works... 
PS C:\WINDOWS\system32>  $Username = 'ZTEST'

 New-SmbShare -name $Username  -Path 'H:\Users\ZTEST'  -FullAccess Everybody  -CimSession servername

Name  ScopeName Path           Description PSComputerName
               
ZTEST *         H:\Users\ZTEST             servername





BUT this doesnt....
PS C:\WINDOWS\system32>  $Username = 'ZTEST'

 New-SmbShare -name $Username  -Path 'H:\Users\'$Username  -FullAccess Everybody  -CimSession servername
New-SmbShare : The parameter is incorrect. 
At line:3 char:2
+  New-SmbShare -name $Username  -Path 'H:\Users\'$Username  -FullAcces ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_SMBShare:ROOT/Microsoft/Windows/S 
   MB/MSFT_SMBShare) [New-SmbShare], CimException
    + FullyQualifiedErrorId : Windows System Error 87,New-SmbShare
    + PSComputerName        : servername

If you have any question or concern, please don't hesitate to let me know.

Best regards,

Michael

 

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]