SMB(Server Message Block)服務(wù)器消息塊協(xié)議
SMB協(xié)議被廣泛應(yīng)用于計(jì)算機(jī)間的文件共享,打印服務(wù)和網(wǎng)絡(luò)瀏覽以及基于網(wǎng)絡(luò)的進(jìn)程間通訊。在Windows平臺(tái)上,SMB協(xié)議常會(huì)與基于TCPIP的NetBIOS協(xié)議一起使用,用到的相關(guān)端口為UPD的137/138以及TCP的137/139,但是NetBIOS不再支持Window Vista、Window Server 2008以及更新的版本,不過(guò)SMB可以不依賴單獨(dú)的通訊協(xié)議而直接通過(guò)TCP/445端口進(jìn)行通訊。
Port 139:SMB協(xié)議原生使用端口139基于NetBIOS進(jìn)行通訊。NetBIOS是一種用于Windows計(jì)算機(jī)間基于網(wǎng)絡(luò)通訊的傳輸層協(xié)議。
Port 445:端口445被用于直接基于TCP/IP的微軟網(wǎng)絡(luò)訪問(wèn),該技術(shù)不再依賴NetBIOS協(xié)議。最新版的SMB服務(wù)使用該端口進(jìn)行通訊。
SMBShare和SMBWitness
SMBShare和SMBWitness模塊于Windows 8和Winows Server 2012開(kāi)始被提供,并在Powershell 3.0以及更新版本中被自動(dòng)加載。這兩個(gè)模塊能夠大大提升文件共享工作的效率并降低其復(fù)雜度。在低于上述版本的系統(tǒng)上,可以使用Windows Management Instrumentation(WMI)來(lái)管理文件共享。
在window平臺(tái)中,上述兩種方法均可在不基于圖形化的場(chǎng)景下,完成對(duì)文件共享的管理工作。
使用WMI來(lái)管理文件共享
在使用WMI模塊來(lái)管理文件共享之前,驗(yàn)證一下是否WMI Provider是否已經(jīng)在系統(tǒng)中安裝。如下命令以及返回信息說(shuō)明WMI模塊在當(dāng)前系統(tǒng)已經(jīng)安裝。如果返回為空則說(shuō)明未安裝WMI,需要下載并安裝Windows Management Framework 3.0。在Windows 7 SP1 和Server 2008 R2 SP1上面可用。
注意,以下所有演示用到的主機(jī)均在同一個(gè)域中,所使用的帳號(hào)都有administrator權(quán)限
PS C:\Windows\system32> Get-WmiObject -Class __Namespace -Namespace root | ? {$_.name -eq 'WMI'}
__GENUS : 2
__CLASS : __NAMESPACE
__SUPERCLASS : __SystemClass
__DYNASTY : __SystemClass
__RELPATH : __NAMESPACE.Name="WMI"
__PROPERTY_COUNT : 1
__DERIVATION : {__SystemClass}
__SERVER : TS1
__NAMESPACE : ROOT
__PATH : \\TS1\ROOT:__NAMESPACE.Name="WMI"
Name : WMI
PSComputerName : TS1
- 使用WMI來(lái)枚舉當(dāng)前系統(tǒng)已存在的共享
Win32_Share存在與root\cimv2的WMI名稱空間中,其中的WMI對(duì)象便是在windows系統(tǒng)之上共享的磁盤、打印機(jī)、系統(tǒng)默認(rèn)共享以及其他共享設(shè)備??梢允褂孟旅娴拿畈樵?/li>
PS C:\Windows\system32> Get-WmiObject -Class win32_share | ft -AutoSize -Wrap
Name Path Description
---- ---- -----------
ADMIN$ C:\Windows Remote Admin
C$ C:\ Default share
IPC$ Remote IPC
test C:\Users\huzx\documents\test
也可以使用Get-WMIObject命令來(lái)查詢遠(yuǎn)程主機(jī)上的共享信息,如下
PS C:\Windows\system32> Get-WmiObject -ComputerName dc -Class win32_share | ft -AutoSize -Wrap
Name Path Description
---- ---- -----------
ADMIN$ C:\Windows 遠(yuǎn)程管理
C$ C:\ 默認(rèn)共享
E$ E:\ 默認(rèn)共享
IPC$ 遠(yuǎn)程 IPC
NETLOGON C:\Windows\SYSVOL\sysvol\buffallos.com\SCRIPTS Logon server share
SYSVOL C:\Windows\SYSVOL\sysvol Logon server share
test c:\test
test1 c:\test1 smbshare test1
- 使用WMI來(lái)創(chuàng)建新的共享
利用WMI來(lái)創(chuàng)建共享,其實(shí)是利用Win32_Share這個(gè)類的方法來(lái)創(chuàng)建,而不是這個(gè)類下面的實(shí)例;所謂類就是Win32_Shared本身,而實(shí)例就是Get-WMIObject -Class Win32_Share所得到的所有對(duì)象。(如仍然不明白,請(qǐng)百度WMI)
可以使用Get-WMIObject命令的-List參數(shù)來(lái)獲取類本身,如下命令將會(huì)創(chuàng)建一個(gè)名為test3的本地共享
PS C:\Windows\system32> new-item -Path c:\ -Name test2 -ItemType directory
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/26/2021 4:54 PM test2
PS C:\Windows\system32> (Get-WmiObject -List -Class win32_share).create("c:\test3","test3",0)
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0
PSComputerName :
如上,新建的對(duì)象實(shí)例,ReturnValue為0,說(shuō)明創(chuàng)建成功,若想更方便的查詢ReturnValue的值,可以將所創(chuàng)建的共享保存成變量后再查詢,如下
PS C:\Windows\system32>$retObj= (Get-WmiObject -List -Class win32_share).create("c:\test3","test3",0)
PS C:\Windows\system32>$retObj.ReturnValue
查看新建的共享
PS C:\Windows\system32> Get-WmiObject -Class win32_share | ? {$_.name -eq 'test3'} | ft -AutoSize -Wrap
Name Path Description
---- ---- -----------
test3 c:\test3
ReturnValue值的不同含義
- 0 - 創(chuàng)建成功
- 2 - 訪問(wèn)被拒絕
- 8 - 未知錯(cuò)誤
- 9 - 名稱不可用
- 10 - 等級(jí)不可用
- 21 - 參數(shù)錯(cuò)誤
- 22 - 重復(fù)的共享
- 23 - 路徑重定向
- 24 - 未知的設(shè)備或目錄
- 25 - 網(wǎng)絡(luò)名稱未找到
使用WMI創(chuàng)建共享的語(yǔ)法如下
(Get-WmiObject -List -Class win32_share).create(PATH,NAME,SHARETYPE)
具體參數(shù)可以通過(guò)以下命令來(lái)查詢PS C:\Windows\system32> ([wmiclass]'win32_share').Create.OverloadDefinitions System.Management.ManagementBaseObject Create(System.String Path, System.String Name, System.UInt32 Type, System.UInt32 MaximumAllowed, System.String Description, System.String Password, System.Management.ManagementObject#Win32_SecurityDescriptor Access)參數(shù):
PATH:共享的路徑,為目標(biāo)主機(jī)本地的絕對(duì)路徑
NAME:自定義共享名稱
SHARETYPE:共享資源的類型共享資源的類型:
- 0 = Disk Drive
- 1 = Print Queue
- 2 = Device * 3 = IPC
- 2147483648 = Disk Drive Admin
- 2147483649 = Print Queue Admin
- 2147483650 = Device Admin
- 2147483651 = IPC Admin
可選參數(shù):
- MaximumAllowed:定義同時(shí)訪問(wèn)該共享資源的最大用戶數(shù)
- Description: 共享資源的描述信息
- Password:為共享資源設(shè)置密碼
- Acess:定義用戶訪問(wèn)權(quán)限的安全描述符。一個(gè)安全描述符包括權(quán)限類型信息,所有者(用戶或者組),對(duì)資源有什么訪問(wèn)權(quán)限
- 使用WMI來(lái)創(chuàng)建遠(yuǎn)程共享
Get-WMIObject命令原生支持遠(yuǎn)程主機(jī)的WMI管理,只需添加-ComputerName參數(shù),如下
PS C:\Windows\system32> new-item -Path //dc/c$ -Name test3 -ItemType directory
Directory: \\dc\c$
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/26/2021 7:10 PM test3
PS C:\Windows\system32> $share=Get-WmiObject win32_share -List -ComputerName dc
PS C:\Windows\system32> $share.create("c:\test3","test3",0)
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0
PSComputerName :
PS C:\Windows\system32> Get-WmiObject -ComputerName dc -Class win32_share | ? {$_.name -eq 'test3'}
Name Path Description
---- ---- -----------
test3 c:\test3
- 使用WMI刪除共享
使用WMI刪除共享,由于刪除操作是對(duì)已有存在的某個(gè)共享操作,因此要用到win32_share對(duì)應(yīng)的具體的實(shí)例的delete方法,如下,將把前面建立的本地共享刪掉
PS C:\Windows\system32> $share=Get-WmiObject -Class win32_share | ? {$_.name -eq 'test3'}
PS C:\Windows\system32> $share
Name Path Description
---- ---- -----------
test3 c:\test3
PS C:\Windows\system32> $share.Delete()
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0
PSComputerName :
PS C:\Windows\system32> Get-WmiObject win32_share
Name Path Description
---- ---- -----------
ADMIN$ C:\Windows Remote Admin
C$ C:\ Default share
IPC$ Remote IPC
test C:\Users\huzx\documents\test
- 使用WMI來(lái)配置共享的訪問(wèn)權(quán)限
在Windows中,權(quán)限由安全描述符來(lái)管理(SDs)。安全描述符包含所有與共享或者其它對(duì)象相關(guān)的訪問(wèn)控制信息。當(dāng)用戶嘗試訪問(wèn)某個(gè)對(duì)象時(shí),Windows使用對(duì)象的安全描述符來(lái)決定用戶是否可以訪問(wèn)這個(gè)對(duì)象。
安全描述符中,自定義的訪問(wèn)控制列表(DACL)是用于訪問(wèn)控制的。DACL包含訪問(wèn)控制條目(ACEs),一條訪問(wèn)控制條目包含以下內(nèi)容:
- 定義當(dāng)前ACE條目行為是
Allow還是deny- 用戶或者組的sid
- 當(dāng)前ACE條目
Allow或Deny的對(duì)象,表示為訪問(wèn)掩碼
可以通過(guò)get-acl命令列出ACL
PS C:\Windows\system32> $share=Get-WmiObject -ComputerName dc -Class win32_share | ? {$_.name -eq 'test3'}
PS C:\Windows\system32> $share
Name Path Description
---- ---- -----------
test3 c:\test3
PS C:\Windows\system32> $share | get-acl | fl *
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\test3
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\
PSChildName : test3
PSDrive : C
PSProvider : Microsoft.PowerShell.Core\FileSystem
CentralAccessPolicyId :
CentralAccessPolicyName :
Path : Microsoft.PowerShell.Core\FileSystem::C:\test3
Owner : BUILTIN\Administrators
Group : buffallos\Domain Users
Access : {System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule,
System.Security.AccessControl.FileSystemAccessRule...}
Sddl : O:BAG:DUD:AI(A;OICIID;FA;;;BA)(A;OICIID;FA;;;SY)(A;OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)
AccessToString : BUILTIN\Administrators Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
BUILTIN\Users Allow ReadAndExecute, Synchronize
NT AUTHORITY\Authenticated Users Allow Modify, Synchronize
NT AUTHORITY\Authenticated Users Allow -536805376
AuditToString :
AccessRightType : System.Security.AccessControl.FileSystemRights
AccessRuleType : System.Security.AccessControl.FileSystemAccessRule
AuditRuleType : System.Security.AccessControl.FileSystemAuditRule
AreAccessRulesProtected : False
AreAuditRulesProtected : False
AreAccessRulesCanonical : True
AreAuditRulesCanonical : True
使用WMI配置安全描述符(SDs)需要用到Set-Acl命令,此命令將與Microsoft .NET Framework classes共同完成SDs的配置。比如,訪問(wèn)權(quán)限(Accessrules)將用到System.Security.AccessControl.FileSystemAccessFule class,這個(gè)類有一個(gè)構(gòu)建access rule的函數(shù),接受一下參數(shù)
- 一個(gè)包含訪問(wèn)資源的目標(biāo)用戶的信息的對(duì)象(IdentityReference)
- 一種文件訪問(wèn)權(quán)限類型值,即定義目標(biāo)用戶分配什么樣子的訪問(wèn)權(quán)限(FileSystemRight)
- 訪問(wèn)控制類型,即
Allow或者Deny(AccessControlType)
為易于理解,請(qǐng)看下面的例子:
PS C:\Windows\system32> $acl = get-acl -Path //dc/c$/test3
PS C:\Windows\system32> $permission = "buffallos\adminhuzx","FullControl","Allow"
PS C:\Windows\system32> $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
PS C:\Windows\system32> $acl.SetAccessRule($accessRule)
PS C:\Windows\system32> $acl | Set-Acl '\\dc\c$\test3'
我們來(lái)分析一下上面的過(guò)程都做了什么?
PS C:\Windows\system32> $acl = get-acl -Path //dc/c$/test3
使用Get-Acl檢索目錄\\dc\c$\test3當(dāng)前的ACL信息。ACL包含有多條ACE,每條ACE都描述某個(gè)用> 戶或組對(duì)所應(yīng)用的資源有何種訪問(wèn)權(quán)限。PS C:\Windows\system32> $permission = "buffallos\adminhuzx","FullControl","Allow"
設(shè)定文件訪問(wèn)控制權(quán)限(FileSystemRule)構(gòu)造函數(shù)所需要的三個(gè)參數(shù)值,它可接受下面三個(gè)參數(shù):
- 當(dāng)前構(gòu)造函數(shù)將應(yīng)用到的用戶(user)
- 當(dāng)前構(gòu)造函數(shù)所定義的權(quán)限類型,比如創(chuàng)建、列出目錄等
- 當(dāng)前構(gòu)造函數(shù)所定義的權(quán)限的訪問(wèn)控制類型,
Allow或者Deny
PS C:\Windows\system32> $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
使用構(gòu)建函數(shù)構(gòu)建文件權(quán)限
PS C:\Windows\system32> $acl.SetAccessRule($accessRule)
在原來(lái)ACL基礎(chǔ)上,添加新的ACE
PS C:\Windows\system32> $acl | Set-Acl '\\dc\c$\test3'
將修改后的ACL應(yīng)用到目錄上
下面是應(yīng)用完新ACL后使用Get-ACL檢索出來(lái)的信息,可以看到有關(guān)新ACE已被應(yīng)用
PS C:\Windows\system32> get-acl -Path '\\dc\c$\test3' | ft -AutoSize -wrap
Directory: \\dc\c$
Path Owner Access
---- ----- ------
test3 BUILTIN\Administrators buffallos\adminhuzx Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
BUILTIN\Administrators Allow FullControl
BUILTIN\Users Allow ReadAndExecute, Synchronize
BUILTIN\Users Allow AppendData
BUILTIN\Users Allow CreateFiles
CREATOR OWNER Allow 268435456
使用SMBShare和SMBWitness模塊來(lái)管理文件共享
使用之前,先導(dǎo)入相應(yīng)模塊
Import-Module SmbShare
Import-Module SmbWitness
- 使用
SMB模塊枚舉當(dāng)前共享
PS C:\Windows\system32> Invoke-Command -ComputerName dc -ScriptBlock {Get-SmbShare}
Name ScopeName Path Description PSComputerName
---- --------- ---- ----------- --------------
ADMIN$ * C:\Windows 遠(yuǎn)程管理 dc
C$ * C:\ 默認(rèn)共享 dc
E$ * E:\ 默認(rèn)共享 dc
IPC$ * 遠(yuǎn)程 IPC dc
NETLOGON * C:\Windows\SYSVOL\sysvol\buffallos.com\SCRIPTS Logon server share dc
SYSVOL * C:\Windows\SYSVOL\sysvol Logon server share dc
test * c:\test dc
test1 * c:\test1 smbshare test1 dc
test3 * c:\test3 dc
- 使用
SMB模塊創(chuàng)建本地共享
可以使用New-SmbShare命令來(lái)創(chuàng)建本地共享,至少提供共享名稱和路徑
PS C:\Windows\system32> New-SmbShare -Name "test4" -Path "c:\"
Name ScopeName Path Description
---- --------- ---- -----------
test4 * c:\
PS C:\Windows\system32> Get-SmbShare
Name ScopeName Path Description
---- --------- ---- -----------
ADMIN$ * C:\Windows Remote Admin
C$ * C:\ Default share
IPC$ * Remote IPC
test * C:\Users\huzx\documents\test
test4 * c:\
可以定義共享的描述信息和預(yù)定義權(quán)限,例如
PS C:\Windows\system32> new-item -Path c:\ -name test6 -ItemType directory
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 3/1/2021 10:54 AM test6
PS C:\Windows\system32> New-SmbShare -Name "test6" -Path "c:\test6" -Description "Test6 shared" -FullAccess buffallos\adminhuzx -ReadAccess everyone
Name ScopeName Path Description
---- --------- ---- -----------
test6 * c:\test6 Test6 shared
PS C:\Windows\system32> Get-SmbShareAccess -Name test6
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
test6 * buffallos\adminhuzx Allow Full
test6 * Everyone Allow Read
```PS C:\Windows\system32> Get-SmbShareAccess -Name test6
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
test6 * buffallos\adminhuzx Allow Full
test6 * Everyone Allow Read
- 使用
SMB模塊創(chuàng)建遠(yuǎn)程共享
使用New-SMBShare有兩種方法可以實(shí)現(xiàn)遠(yuǎn)程共享的創(chuàng)建
- 使用
-Cimsession參數(shù)
PS C:\Windows\system32> New-Item -Path //dc/c$ -name test6 -ItemType directory Directory: \\dc\c$ Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 3/1/2021 1:34 PM test6 PS C:\Windows\system32> New-SmbShare -Name test6 -CimSession DC -Path c:\test6 -FullAccess "buffallos\adminhuzx" -ChangeAccess everyone -Description "Test6 on DC" Name ScopeName Path Description PSComputerName ---- --------- ---- ----------- -------------- test6 * c:\test6 Test6 on DC DC PS C:\Windows\system32> get-smbshare -Name test6 -CimSession dc | ft -AutoSize -wrap Name ScopeName Path Description PSComputerName ---- --------- ---- ----------- -------------- test6 * c:\test6 Test6 on DC dc PS C:\Windows\system32> Get-SmbShareAccess -Name test6 -CimSession dc Name ScopeName AccountName AccessControlType AccessRight PSComputerName ---- --------- ----------- ----------------- ----------- -------------- test6 * buffallos\adminhuzx Allow Full dc test6 * Everyone Allow Change dc
- 使用
PowerShell的Invoke-Command命令
PS C:\Windows\system32> Invoke-Command -ComputerName dc -ScriptBlock {new-item -Path c:\ -Name test7 -ItemType directory;New-SmbShare -Name "Test7" -Path c:\test7 -FullAccess "buffallos\adminhuzx" -ChangeAccess everyone -Description "Test7 on DC"} Directory: C:\ Mode LastWriteTime Length Name PSComputerName ---- ------------- ------ ---- -------------- d----- 3/1/2021 1:44 PM test7 dc PresetPathAcl : System.Security.AccessControl.DirectorySecurity PSComputerName : dc RunspaceId : 2258cb4b-7968-4a03-a66b-1fe80e8ba5ee AvailabilityType : NonClustered CachingMode : Manual CATimeout : 0 ConcurrentUserLimit : 0 ContinuouslyAvailable : False CurrentUsers : 0 Description : Test7 on DC EncryptData : False FolderEnumerationMode : Unrestricted Name : Test7 Path : c:\test7 Scoped : False ScopeName : * SecurityDescriptor : O:SYG:SYD:(A;;FA;;;S-1-5-21-1922697842-2877171228-2226451015-1107)(A;;0x1301bf;;;WD) ShadowCopy : False ShareState : Online ShareType : FileSystemDirectory SmbInstance : Default Special : False Temporary : False Volume : \\?\Volume{d524dd8e-0000-0000-0000-501f00000000}\ LeasingMode : PS C:\Windows\system32> Get-SmbShare -Name test7 -CimSession dc | ft -AutoSize -Wrap Name ScopeName Path Description PSComputerName ---- --------- ---- ----------- -------------- Test7 * c:\test7 Test7 on DC dc PS C:\Windows\system32> Get-SmbShareAccess -Name test7 -CimSession DC Name ScopeName AccountName AccessControlType AccessRight PSComputerName ---- --------- ----------- ----------------- ----------- -------------- Test7 * buffallos\adminhuzx Allow Full DC Test7 * Everyone Allow Change DC
- 使用
SMBShare模塊刪除共享
刪除共享可以使用Remove-SmbShare后面直接跟共享名即可
PS C:\Windows\system32> Remove-SmbShare -Name test6
PS C:\Windows\system32> Get-SmbShare
Name ScopeName Path Description
---- --------- ---- -----------
ADMIN$ * C:\Windows Remote Admin
C$ * C:\ Default share
IPC$ * Remote IPC
test * C:\Users\huzx\documents\test
test4 * c:\
test5 * c:\
要?jiǎng)h除遠(yuǎn)程主機(jī)上的共享,只需使用-Cimsession指定主機(jī)名稱即可
PS C:\Windows\system32> Get-SmbShare -CimSession dc
Name ScopeName Path Description PSComputerName
---- --------- ---- ----------- --------------
ADMIN$ * C:\Windows 遠(yuǎn)程管理 dc
C$ * C:\ 默認(rèn)共享 dc
E$ * E:\ 默認(rèn)共享 dc
IPC$ * 遠(yuǎn)程 IPC dc
NETLOGON * C:\Windows\SYSVOL\sysvol\buffallos.com\SCRIPTS Logon server share dc
SYSVOL * C:\Windows\SYSVOL\sysvol Logon server share dc
test * c:\test dc
test1 * c:\test1 smbshare test1 dc
test3 * c:\test3 dc
test6 * c:\test6 Test6 on DC dc
Test7 * c:\test7 Test7 on DC dc
PS C:\Windows\system32> Remove-SmbShare -CimSession dc -Name test6
PS C:\Windows\system32> Get-SmbShare -CimSession dc
Name ScopeName Path Description PSComputerName
---- --------- ---- ----------- --------------
ADMIN$ * C:\Windows 遠(yuǎn)程管理 dc
C$ * C:\ 默認(rèn)共享 dc
E$ * E:\ 默認(rèn)共享 dc
IPC$ * 遠(yuǎn)程 IPC dc
NETLOGON * C:\Windows\SYSVOL\sysvol\buffallos.com\SCRIPTS Logon server share dc
SYSVOL * C:\Windows\SYSVOL\sysvol Logon server share dc
test * c:\test dc
test1 * c:\test1 smbshare test1 dc
test3 * c:\test3 dc
Test7 * c:\test7 Test7 on DC dc
5.使用SMBShare模塊來(lái)配置訪問(wèn)權(quán)限
由上面的創(chuàng)建共享的例子看到,New-SMBShare可以通過(guò)參數(shù)進(jìn)行預(yù)設(shè)置權(quán)限,相關(guān)參數(shù):
- -FullAccess
- -ChangeAccess
- -ReadAccess
- -NoAccess
見(jiàn)文知義,上面的參數(shù)都很好理解;但是更為精細(xì)的權(quán)限分配卻無(wú)能為力,這個(gè)時(shí)候咱們就可以使用Grant-SMBShareAccess命令來(lái)設(shè)置權(quán)限。為完成權(quán)限的分配,該命令有兩個(gè)參數(shù):
- -AccountName 需要分配權(quán)限的用戶或者組
- -AccessRight 需要分配給目標(biāo)用戶或組什么權(quán)限,可以接受的值為
Full,Change和Read
PS C:\Windows\system32> Get-SmbShareAccess -name test
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
test * Everyone Allow Read
PS C:\Windows\system32> Grant-SmbShareAccess -name test -AccountName "buffallos\adminhuzx" -AccessRight Full
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
test * Everyone Allow Read
test * buffallos\adminhuzx Allow Full
若需要吊銷某個(gè)用戶的權(quán)限,可以使用Revoke-SmbShareAccess命令
PS C:\Windows\system32> Grant-SmbShareAccess -name test -AccountName "buffallos\adminhuzx" -AccessRight Full
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
test * Everyone Allow Read
test * buffallos\adminhuzx Allow Full
PS C:\Windows\system32> Revoke-SmbShareAccess -Name test -AccountName "buffallos\adminhuzx"
Name ScopeName AccountName AccessControlType AccessRight
---- --------- ----------- ----------------- -----------
test * Everyone Allow Read
Grant-SmbShareAccess與Revoke-SmbShareaccess 同樣擁有-CimSession參數(shù),以實(shí)現(xiàn)遠(yuǎn)程共享的管理