当路径是变量时,新SMBShare不工作

时间:2017-12-06 17:41:45

标签: powershell

以下工作:

$ New-SMBShare  -name "xyz$" -Path "C:\TEMP\smbshare4" -FullAccess "NT AUTHORITY\Authenticated Users"

但不是我将-path作为变量$dirPath="C:\TEMP\\smbshare4"

传递的地方
$ New-SMBShare  -name "xyz$" -Path  $dirPath  -FullAccess "NT AUTHORITY\Authenticated Users"

New-SMBShare : The filename, directory name, or volume label syntax is incorrect.
At line:1 char:1
+ New-SMBShare  -name "xyz$" -Path  $dirPath  -FullAccess "NT AUTHORITY\Authentica ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare) [New-SmbShare], CimException
+ FullyQualifiedErrorId : Windows System Error 123,New-SmbShare

1 个答案:

答案 0 :(得分:0)

双向反斜杠“\”是问题所在。

$ dirPath =“C:\ TEMP \ smbshare4”工作。