New-SmbShare 未更新 'Network file and folder sharing '
New-SmbShare not updating 'Network file and folder sharing '
我想从 Powershell 设置 SmbShare,
我已经创建了文件夹并更改了高级共享,
但是 'Network file and folder sharing' 没有更新。
这意味着网络上的其他用户无法访问此文件夹。
new-item -Name foobar -Path C:\ -ErrorAction SilentlyContinue -ItemType directory -Verbose
New-SmbShare -Name foobar -Path C:\foobar -FullAccess everyone -Verbose
如何更新 'Network file and folder sharing' 中的 'group or user names'
(GUI 除外)
我在下面附上了 GUI 屏幕截图。
正在按预期更新高级共享:
但它没有更新 'Network file and folder sharing'
我本以为会看到这个:
感谢您发布此内容。不确定,但尝试将其合并到您的脚本中
安装-SmbShare -Name MyShare -Path X:\ -FullAccess 'Everybody'
我需要通过 ACL 而不是 SMBshare 来执行此操作。
我写了一个函数来更轻松地更改设置。
Set-NetworkShareAccess -path "C:\foobara" -Confirm
我的函数:
function Set-NetworkShareAccess
{
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact='Medium'
)]
Param
(
[ValidateSet(
'ReadData', 'WriteData', 'CreateFiles', 'CreateDirectories', 'AppendData',
'ReadExtendedAttributes', 'WriteExtendedAttributes', 'Traverse', 'ExecuteFile',
'DeleteSubdirectoriesAndFiles', 'ReadAttributes', 'WriteAttributes', 'Write', 'Delete',
'ReadPermissions', 'Read','ReadAndExecute', 'Modify', 'ChangePermissions', 'TakeOwnership',
'Synchronize', 'FullControl'
)]
$PermissionLevel = 'FullControl',
[Parameter(Mandatory=$true)]
$path = "C:\foobara",
$User = 'everyone',
[ValidateSet('None', 'NoPropagateInherit', 'InheritOnly')]
$recursive = 'None'
)
New-SmbShare -Name ([System.IO.FileInfo]$path).Name -Path $path -FullAccess $User | Out-Null
$Acl = Get-Acl -Path $path
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("$User", "$PermissionLevel", "ContainerInherit,ObjectInherit", "$recursive", "Allow")
$Acl.SetAccessRule($Ar)
Set-Acl -Path $path -AclObject $Acl
}
我想从 Powershell 设置 SmbShare, 我已经创建了文件夹并更改了高级共享, 但是 'Network file and folder sharing' 没有更新。 这意味着网络上的其他用户无法访问此文件夹。
new-item -Name foobar -Path C:\ -ErrorAction SilentlyContinue -ItemType directory -Verbose
New-SmbShare -Name foobar -Path C:\foobar -FullAccess everyone -Verbose
如何更新 'Network file and folder sharing' 中的 'group or user names' (GUI 除外)
我在下面附上了 GUI 屏幕截图。
正在按预期更新高级共享:
但它没有更新 'Network file and folder sharing'
我本以为会看到这个:
感谢您发布此内容。不确定,但尝试将其合并到您的脚本中 安装-SmbShare -Name MyShare -Path X:\ -FullAccess 'Everybody'
我需要通过 ACL 而不是 SMBshare 来执行此操作。
我写了一个函数来更轻松地更改设置。
Set-NetworkShareAccess -path "C:\foobara" -Confirm
我的函数:
function Set-NetworkShareAccess
{
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact='Medium'
)]
Param
(
[ValidateSet(
'ReadData', 'WriteData', 'CreateFiles', 'CreateDirectories', 'AppendData',
'ReadExtendedAttributes', 'WriteExtendedAttributes', 'Traverse', 'ExecuteFile',
'DeleteSubdirectoriesAndFiles', 'ReadAttributes', 'WriteAttributes', 'Write', 'Delete',
'ReadPermissions', 'Read','ReadAndExecute', 'Modify', 'ChangePermissions', 'TakeOwnership',
'Synchronize', 'FullControl'
)]
$PermissionLevel = 'FullControl',
[Parameter(Mandatory=$true)]
$path = "C:\foobara",
$User = 'everyone',
[ValidateSet('None', 'NoPropagateInherit', 'InheritOnly')]
$recursive = 'None'
)
New-SmbShare -Name ([System.IO.FileInfo]$path).Name -Path $path -FullAccess $User | Out-Null
$Acl = Get-Acl -Path $path
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("$User", "$PermissionLevel", "ContainerInherit,ObjectInherit", "$recursive", "Allow")
$Acl.SetAccessRule($Ar)
Set-Acl -Path $path -AclObject $Acl
}