I want to set up a SmbShare from Powershell, I have created the folder and changed the Advanced sharing, but the 'Network file and folder sharing' is not updating. This means that other users on the network are unable to access this folder.
new-item -Name foobar -Path C:\ -ErrorAction SilentlyContinue -ItemType directory -Verbose
New-SmbShare -Name foobar -Path C:\foobar -FullAccess everyone -Verbose
How do I update the 'group or user names' in 'Network file and folder sharing' (Other than with the GUI)
I have attached the GUI screenshots below.
It is updating the Advanced sharing as expected:
I needed to do this though ACL rather than SMBshare.
I wrote a function to change the setting more easily.
Set-NetworkShareAccess -path "C:\foobara" -Confirm
My Function:
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
}