Assigning File Share permissions using Power Shell

Recently I was working on some Power Shell scripts for configuring my Windows Server 2012 machines. One of the task was to create a File share on a remote server and then share it and then assign NTFS and Share permissions.

Assigning NTFS permissions was simple however for assigning share permissions, I have to search a lot and luckily I found that in Windows 2012, a cmdlet is being added for this purpose and below is how I achieved this.

Obviously i took the names of remote server and share name as input in variables as $QServer and $QShare

# Make the folder

$FullPath= “\\”+$QServer+”\c$\”+$QShare
mkdir $FullPath

# Create the File Share

(get-wmiobject -list -ComputerName $QServer |Where-Object -FilterScript {$_.Name -eq “Win32_Share”}).InvokeMethod(“Create”,($Path,$QShare,0,100,”My Directory”))

# Assign the NTFS Permissions to Administrators

$AccessRule =New-Object System.Security.AccessControl.FileSystemAccessRule(“Administrators”,”FullControl”,”ContainerInherit,ObjectInherit”,”None”,”Allow”)
$ACL=get-acl \\$QServer\$QShare
set-acl \\$QServer\$QShare -AclObject $acl

# Remove “Everyone” from Share permissions and assign the Share Permissions to “Administrators”

Revoke-SmbShareAccess -name $QShare -CimSession $QServer -AccountName Everyone -Force
Grant-SmbShareAccess -name $QShare -CimSession $QServer -AccountName Administrators -AccessRight Full –Force

I hope this will be helpful for people working on similar tasks.

Cheers !!

Comments (43)

  1. Anonymous says:

    We are pleased to announce the RTM availability of version 9.0 of the Microsoft Assessment and Planning

  2. Anonymous says:

    I’ve written a few blog posts now that get into the deep technical details of Managed Availability. I

  3. Anonymous says:

    Recently I was involved in a Private Cloud project and as part of the project, we were migrating some

  4. Anonymous says:

    Recently, we have seen some questions about what the Update-DatabaseSchema cmdlet in Exchange 2013 is

  5. Anonymous says:

    This has been a great new feature added in Windows Server 2012 R2. The possible scenario of the usage

  6. Anonymous says:

    Many users rely on their smart phones and other mobile devices to access their email and calendar using

  7. Anonymous says:

    With Exchange 2013, we released a new data loss prevention (DLP) capability based on deep content analysis

  8. Anonymous says:

    Exchange Server 2013 Service Pack 1 (SP1) is now available for download! Please make sure to read the

  9. Dan Gøran Lunde says:

    The AccessRule is not displayed correctly. The correct rule should be:

    $AccessRule =New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl","ContainerInherit,ObjectInherit","None","Allow")

  10. Anonymous says:

    This article is part 2 in a series that discusses namespace planning , load balancing principles, client

  11. Anonymous says:

    Microsoft Exchange Server 2003 entered the market on September 28, 2003 and continued the great messaging

  12. Anonymous says:

    Now that we understand the load balancing and namespace planning principles and how clients connect in

  13. Anonymous says:

    We’re happy to announce updates to the Exchange Server Deployment Assistant ! These updates offer you

  14. Anonymous says:

    During my session at the recent Microsoft Exchange Conference (MEC), I revealed Microsoft’s preferred

  15. Anonymous says:

    With the huge scale environment I currently work in my team has had some difficulty when it comes to

  16. Anonymous says:

    I recently did an Exchange 2013 deployment at one of our customers and also integrated with ADRMS so

  17. Anonymous says:

    In the last week there have been two big improvements related to CalCheck and OffCAT that will make life

  18. Anonymous says:

    I was recently helping a customer in ADRMS design and deployment where we faced an issue with ADRMS URL

  19. Anonymous says:

    We are pleased to announce the availability of version 9.1 of the Microsoft Assessment and Planning

  20. Anonymous says:

    Recently I was working for ADRMS integration with Exchange which is rather simple however it became quite

  21. Anonymous says:

    Probes are one of the three critical parts of the Managed Availability framework (monitors and responders

  22. Anonymous says:

    In the last related blog post we gave some introduction about Exchange Online Protection (EOP), what

  23. Anonymous says:

    The Exchange team is announcing today the availability of our most recent quarterly servicing update

  24. Anonymous says:

    Occasionally I am asked the following question – how can I protect the messaging environment from a rogue

  25. Anonymous says:

    Bulk mail is often mistaken for spam and is starting to become a larger problem for organizations. EOP

  26. Anonymous says:

    At The Official Microsoft Blog , we revealed more details about our unified technology event for event

  27. Anonymous says:

    We recently released updated versions of both the Exchange 2010 Server Role Requirements Calculator and

  28. Anonymous says:

    What are we talking about today? In Exchange 2013 CU5 (yes 5, V, cinco, fem, and cinque) we started implementing

  29. Anonymous says:

    I was recently working with one of our customers on Lync 2013 project and one of the questions customer

  30. Anonymous says:

    I was recently working on a project using Security Compliance Manager (SCM) for Active Directory based

  31. Anonymous says:

    I was recently working with a customer helping them migrate to the Eliminated state of Sysvol migration

  32. Anonymous says:

    Back at the release of Exchange Server 2013 CU1 we made some necessary changes to the way OWA logoff

  33. Anonymous says:

    This morning we published the first look at the Ignite session catalog providing you a better view of

  34. Anonymous says:

    Sometime ago, I wrote a blog about upgrading from Windows 2003 based Active Directory to Windows 2008

  35. Anonymous says:

    Exchange team has released a blog about Office 365 best practices analyzer for Exchange 2013 as below

  36. Anonymous says:

    Exchange team has written a blog about new Exchange Server deployment assistance as below:


  37. Anonymous says:

    You can protect your organizational Units from accidental deletion by using Power Shell scripts to apply

  38. Anonymous says:

    I was recently working with a customer where one of their Active Directory would not replicate. They

  39. Anonymous says:

    Recently Microsoft Exchange team has written a blog about large messages in Office 365. I see many customers

  40. Anonymous says:

    Microsoft has recently released an initial look at Exchange 2016 architecture and Exchange team has written

  41. Anonymous says:

    Recently Exchange team has written an excellent article on Exchange processor and memory usage and how

  42. Anonymous says:

    In a recent project I was working on ADFS with multiple applications and customer also had SAP to be

  43. Anonymous says:

    Recently i was troubleshooting some integration issues between SCVMM, SPF and Windows Azure Pack (WAP