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
$Path="c:\"+$QShare
# 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
$ACL.SetAccessRule($AccessRule)
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
- Anonymous
December 18, 2013
We are pleased to announce the RTM availability of version 9.0 of the Microsoft Assessment and Planning - Anonymous
December 18, 2013
I’ve written a few blog posts now that get into the deep technical details of Managed Availability. I - Anonymous
December 26, 2013
Recently I was involved in a Private Cloud project and as part of the project, we were migrating some - Anonymous
January 14, 2014
Recently, we have seen some questions about what the Update-DatabaseSchema cmdlet in Exchange 2013 is - Anonymous
January 30, 2014
This has been a great new feature added in Windows Server 2012 R2. The possible scenario of the usage - Anonymous
February 09, 2014
Many users rely on their smart phones and other mobile devices to access their email and calendar using - Anonymous
February 25, 2014
With Exchange 2013, we released a new data loss prevention (DLP) capability based on deep content analysis - Anonymous
February 26, 2014
Exchange Server 2013 Service Pack 1 (SP1) is now available for download! Please make sure to read the - Anonymous
March 03, 2014
The AccessRule is not displayed correctly. The correct rule should be:
$AccessRule =New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl","ContainerInherit,ObjectInherit","None","Allow") - Anonymous
March 05, 2014
This article is part 2 in a series that discusses namespace planning , load balancing principles, client - Anonymous
March 10, 2014
Microsoft Exchange Server 2003 entered the market on September 28, 2003 and continued the great messaging - Anonymous
March 20, 2014
Now that we understand the load balancing and namespace planning principles and how clients connect in - Anonymous
April 18, 2014
We’re happy to announce updates to the Exchange Server Deployment Assistant ! These updates offer you - Anonymous
April 21, 2014
During my session at the recent Microsoft Exchange Conference (MEC), I revealed Microsoft’s preferred - Anonymous
May 02, 2014
With the huge scale environment I currently work in my team has had some difficulty when it comes to - Anonymous
May 25, 2014
I recently did an Exchange 2013 deployment at one of our customers and also integrated with ADRMS so - Anonymous
June 18, 2014
In the last week there have been two big improvements related to CalCheck and OffCAT that will make life - Anonymous
June 18, 2014
I was recently helping a customer in ADRMS design and deployment where we faced an issue with ADRMS URL - Anonymous
June 27, 2014
We are pleased to announce the availability of version 9.1 of the Microsoft Assessment and Planning - Anonymous
July 02, 2014
Recently I was working for ADRMS integration with Exchange which is rather simple however it became quite - Anonymous
August 11, 2014
Probes are one of the three critical parts of the Managed Availability framework (monitors and responders - Anonymous
August 19, 2014
In the last related blog post we gave some introduction about Exchange Online Protection (EOP), what - Anonymous
August 26, 2014
The Exchange team is announcing today the availability of our most recent quarterly servicing update - Anonymous
September 16, 2014
Occasionally I am asked the following question – how can I protect the messaging environment from a rogue - Anonymous
September 28, 2014
Bulk mail is often mistaken for spam and is starting to become a larger problem for organizations. EOP - Anonymous
October 20, 2014
At The Official Microsoft Blog , we revealed more details about our unified technology event for event - Anonymous
October 25, 2014
We recently released updated versions of both the Exchange 2010 Server Role Requirements Calculator and - Anonymous
November 09, 2014
What are we talking about today? In Exchange 2013 CU5 (yes 5, V, cinco, fem, and cinque) we started implementing - Anonymous
November 30, 2014
I was recently working with one of our customers on Lync 2013 project and one of the questions customer - Anonymous
December 23, 2014
I was recently working on a project using Security Compliance Manager (SCM) for Active Directory based - Anonymous
December 31, 2014
I was recently working with a customer helping them migrate to the Eliminated state of Sysvol migration - Anonymous
January 13, 2015
Back at the release of Exchange Server 2013 CU1 we made some necessary changes to the way OWA logoff - Anonymous
January 31, 2015
This morning we published the first look at the Ignite session catalog providing you a better view of - Anonymous
February 08, 2015
Sometime ago, I wrote a blog about upgrading from Windows 2003 based Active Directory to Windows 2008 - Anonymous
February 09, 2015
Exchange team has released a blog about Office 365 best practices analyzer for Exchange 2013 as below - Anonymous
February 09, 2015
Exchange team has written a blog about new Exchange Server deployment assistance as below:
We’ve - Anonymous
February 15, 2015
You can protect your organizational Units from accidental deletion by using Power Shell scripts to apply - Anonymous
March 23, 2015
I was recently working with a customer where one of their Active Directory would not replicate. They - Anonymous
April 24, 2015
Recently Microsoft Exchange team has written a blog about large messages in Office 365. I see many customers - Anonymous
May 12, 2015
Microsoft has recently released an initial look at Exchange 2016 architecture and Exchange team has written - Anonymous
June 30, 2015
Recently Exchange team has written an excellent article on Exchange processor and memory usage and how - Anonymous
July 31, 2015
In a recent project I was working on ADFS with multiple applications and customer also had SAP to be - Anonymous
December 13, 2015
Recently i was troubleshooting some integration issues between SCVMM, SPF and Windows Azure Pack (WAP