Grant SmbShareAccess - PowerShell


Overview

Grant-SmbShareAccess grants permissions to specified user accounts or security groups to access a file share on an SMB server. It adds the specified permissions to the existing permissions on the share.

Syntax

Grant-SmbShareAccess [-Name] <String> -Path <String> -AccessRight <String[]> [-Force] [-Confirm] [-WhatIf] [-Credential <PSCredential>] [<CommonParameters>]

Options/Flags

  • -Name (Required): Name of the file share to grant access to.
  • -Path (Required): Path to the file share, in the format Server\ShareName.
  • -AccessRight (Required): Permission to grant. Multiple permissions can be specified. Valid values include:
    • Read
    • Change
    • FullControl
  • -Force: Suppresses confirmation prompts.
  • -Confirm: Prompts for confirmation before executing the command.
  • -WhatIf: Simulates the command without making any changes.
  • -Credential: Specifies the credentials to use when connecting to the SMB server.

Examples

Basic Usage:

Grant-SmbShareAccess -Name Share1 -Path Server1\Share1 -AccessRight Read

Grant Multiple Permissions:

Grant-SmbShareAccess -Name Share1 -Path Server1\Share1 -AccessRight Read,Change

Force Permission Granting:

Grant-SmbShareAccess -Name Share1 -Path Server1\Share1 -AccessRight FullControl -Force

Common Issues

  • Ensure that the specified user account or security group has a valid SID.
  • Verify that the user running the command has sufficient permissions to grant access to the share.
  • Check if the SMB server is accessible and properly configured.

Integration

Combine Grant-SmbShareAccess with other PowerShell commands, such as Get-SmbShare and Test-SmbShareAccess, for managing SMB share permissions and testing access.

  • Get-SmbShare: Gets information about SMB shares.
  • Remove-SmbShareAccess: Removes permissions for user accounts or security groups from an SMB share.
  • Test-SmbShareAccess: Tests access permissions for a specified user account or security group on an SMB share.