【问题标题】:Powershell - Invoke-WmiMethod to create a Sharefolder remotely with full controle permissionPowershell - Invoke-WmiMethod 以完全控制权限远程创建共享文件夹
【发布时间】:2013-01-15 20:08:52
【问题描述】:

我一直在使用这个脚本来创建我的用户文件夹,但我发现远程共享文件夹是使用只读共享创建的。

我的问题是如何使用$domainname\domain 用户和full control 创建共享文件夹?

Invoke-WmiMethod -Class win32_share -name Create -ArgumentList `
 @($null,"",100,"hideshare$","",e:\users\hideshare,0) -computername "DestinationSRV"

我找到了很多答案,但我使用的方法却没有。

有什么想法吗?

【问题讨论】:

    标签: powershell wmi share


    【解决方案1】:

    试试:

    #Username/Group to give permissions to
    $trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
    $trustee.Domain = "domainname"
    $trustee.Name = "username or groupname"
    
    #Accessmask values
    $fullcontrol = 2032127
    $change = 1245631
    $read = 1179785
    
    #Create access-list
    $ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
    $ace.AccessMask = $fullcontrol
    $ace.AceFlags = 3
    $ace.AceType = 0
    $ace.Trustee = $trustee
    
    #Securitydescriptor containting access
    $sd = ([wmiclass]'Win32_SecurityDescriptor').psbase.CreateInstance()
    $sd.ControlFlags = 4
    $sd.DACL = $ace
    $sd.group = $trustee
    $sd.owner = $trustee
    
    $share = Get-WmiObject Win32_Share -List -ComputerName "DestinationSRV"
    $share.create("e:\users\hideshare", "hideshare$", 0, 100, "Description", "", $sd)
    

    此共享的安全性将只允许指定的用户名。您需要修改此(添加多个 ace)以添加不同的组、添加每个人等。

    Source for access-part

    【讨论】:

    • 仅供参考:这只会创建一个具有共享权限的共享对象。文件夹的 ntfs 权限是另一回事。并在服务器管理方面采取一些最佳实践。在大多数情况下,您希望允许每个人完全共享访问权限,并将其锁定在 ntfs(文件夹/文件)级别。两者中最严格的(共享和 ntfs 权限)是使用的那个。因此,在共享权限中被阻止 + 允许的 ntfs = 从远程位置阻止,并在服务器上本地允许。在共享中允许 + 在 ntfs 中阻止 = 阻止远程和本地。因此,如果可能,请使用 ntfs 阻止访问。更容易维护
    • 好吧,我刚完成测试,收到一个错误:Invoke-WmiMethod : Invalid operation 'At line:1 char:17 + Invoke-WmiMethod
    • 感谢 NTFS 右侧的提示我调用了另一个 PS 函数,这部分工作正常。
    • 如果我将 $sd 替换为 $null 脚本可以正常工作吗?
    • 当然,我把我的域和我的用户名让我在本地路径上再试一次
    猜你喜欢
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多