Posted On August 5, 2021

PowerShell: Create and Edit SMB Shares

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Create and Edit SMB Shares
# Create SMB Share
$sharePath='C:\testshare'
$accessList="$env:USERDOMAIN\Domain Admins","NT AUTHORITY\Authenticated Users"
$shareName=split-path $sharePath -leaf
mkdir $sharePath
New-SmbShare -Name $shareName -Path $sharePath -FullAccess $accessList

# Check SMB Acccesses
[SMBSERVER]: PS C:\Users\kimconnect\Documents> Get-SmbShareAccess $shareName
Name          ScopeName AccountName                      AccessControlType AccessRight
----          --------- -----------                      ----------------- -----------
testshare *         KIMCONNECT\Domain Admins         Allow             Full
testshare *         NT AUTHORITY\Authenticated Users Allow             Full

# Add Share Permissions
$grantPrinciple="$env:USERDOMAIN\Domain Admins"
Grant-SmbShareAccess -Name $shareName -AccountName $grantPrinciple -AccessRight Full -Force

# Remove Share Permissions
$removePrinciple="NT AUTHORITY\Authenticated Users"
Revoke-SmbShareAccess -Name $shareName -AccountName $removePrinciple -Force

# Clone NTFS Access Control List (ACL)
# Warning: only do this to a new clone-to directory as misuse can cause permission problems
$cloneAclFrom='C:\originalshare'
$cloneAclTo=$sharePath
get-acl $cloneAclFrom|set-acl $cloneAclTo

# Check NTFS Permissions:
[SMBSERVER]: PS C:\Users\kimconnect\Documents> (get-acl c:\testshare).AccessToString
Everyone Allow  ReadAndExecute, Synchronize
CREATOR OWNER Allow  FullControl
NT AUTHORITY\SYSTEM Allow  FullControl
BUILTIN\Administrators Allow  FullControl
KIMCONNECt\TestAdmin Allow  FullControl

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Get SQL Server Performance Counters

Version 2 # getSqlPerformanceCounter.ps1 # version 0.02 $computername='sql0003.kimconnect.com' function getSqlPerformanceCounter($server=$env:computername,$sampleInterval=10,$maxSamples=1){ $PerformanceCounterSampleSet=$result=@() $counters=@( '\Memory\Available MBytes', '\Memory\Pages/sec',…

PowerShell: Create and Delete VSS Snapshots

Update 7/30/20: use this newer version # There are 2 functions in this snippet# 1.…

FTP On Upload Email

# Connection details# If your SMTP server does not support SSL, remove the -UseSSL parameter…