0

我需要從Powershell 4腳本設置遠程共享的共享權限。我查看了this page,特別是命令Grant-SmbShareAccess,但該cmdlet設置了本地共享的權限,我很想看到-ComputerName參數,但是,唉,沒有一個。如何使用Powershell設置遠程共享的共享權限?

我想做的事情是這樣的:Grant-SmbShareAccess -ComputerName MYREMOTESERVER -Name <share_name> -AccountName <domain_account> -AccessRight Full

如何做到這一點任何想法?我的遠程服務器可能是Windows Server或NetApp vFiler。

編輯

我試過的Invoke-Command馬特的建議,在與NetApp的vFiler的意見,並得到這個錯誤:

Connecting to remote server MYREMOTESERVER failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".

更改共享的安全性在Windows資源管理器工作正常。

+0

也許'調用,Command'是你在找什麼。更多信息[這裏](http://technet.microsoft.com/en-us/library/hh849719.aspx) – Matt 2014-09-04 12:07:19

+0

@Matt如果我只是處理遠程Windows服務器,我會看看,但如果遠程共享託管在NetApp vFiler上,我認爲這不會起作用,因爲它取決於遠程處理。 – 2014-09-04 12:15:43

+0

您是否嘗試過將服務器名稱與共享名稱一起傳遞?類似於:'Grant-SmbShareAccess -Name \\ MYREMOTESERVER \ SHARENAME -AccountName USERACCOUNT -AccessRight Full' – CitizenRon 2014-09-04 21:27:00

回答

0

Grant-SmbShareAccess是一個CDXML命令,這意味着它使用CIM。正如您已經注意到的那樣,它只能在運行至少PSv3的Windows系統上運行(在這種情況下,所使用的WMI類只存在於Windows 8和Server 2012或更高版本中)。

可能有其他的方法可以做到這對非Windows服務器上,但我會嘗試PowerShell Access Control Module

$SharePath = "\\ServerName\ShareName" 
$Principal = <account name here> 

# Add permission to $Principal (-Force will suppress the prompt) 
Get-SecurityDescriptor -Path $SharePath -ObjectType LMShare | 
    Add-AccessControlEntry -Principal $Principal -LogicalShareRights FullControl -Apply #-Force 

# Verify: 
Get-SecurityDescriptor -Path $SharePath -ObjectType LMShare | 
    Get-AccessControlEntry 

老實說,我不知道,因爲我只測試了它,這將工作對Windows服務器,我不經常處理共享權限。嘗試一下,如果它起作用,我會從答案中拿出這部分。

+0

謝謝,有什麼方法可以不使用該模塊?我正在嘗試使用Windows Server上的默認工具集來完成此操作。 – 2014-09-09 11:23:52

+0

也許,但我不知道一個。模塊是否工作?如果是這樣,我可以修改答案,以包含一個更短的PowerShell腳本,它只包含P/Invoke簽名和PS /。NET代碼需要得到它的工作(不需要模塊)。 – 2014-09-09 16:50:23

0

對於Windows Server SMB共享,​​請使用-CimSession參數。

對於非Windows SMB共享,​​我不希望Windows SMB管理cmdlet可以與它們一起使用。

0

Netapp Powershell工具包將爲此提供幫助。安裝後,您可以將模塊導入到腳本中,並管理您的共享。下面是一個連接到文件管理器粗略例如,提示輸入共享名,然後配置該共享一些默認的權限:

# Import the Netapp Powershell Module 
import-module dataontap 

# Connect to the filer 
connect-nacontroller *filername* 

# Get the sharename 
$sharename = Read-Host -Prompt 'Enter the share you want to configure' 

# Configure the CIFS Permissions 
Set-NaCifsShareAcl $sharename "Authenticated users" -AccessRights "Change" 
Set-NaCifsShareAcl $sharename filername\administrators -AccessRights "Full Control" 
Set-NaCifsShareAcl $sharename domain\somegroup -AccessRights "Full Control" 
Remove-NaCifsShareAcl $sharename everyone