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