Powershell - 调用 WmiMethod 以远程创建具有完全控制权限的共享文件夹 [英] Powershell - Invoke-WmiMethod to create a Sharefolder remotely with full controle permission

查看:41
本文介绍了Powershell - 调用 WmiMethod 以远程创建具有完全控制权限的共享文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been using this script to create my users folders but I just find that the remote share folder is created with ReadOnly share.

我的问题是如何与具有 完全控制$domainname\domain 用户创建共享文件夹?

My question is how can I create the share folder with $domainname\domain users with full control?

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

我找到了很多有答案的帖子,但不是我使用的方法.

I've found many threads with answers but not with the method I use.

有什么想法吗?

推荐答案

尝试:

#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的)来添加不同的组,添加每个人等等.

The security for this share will only allow the specified username. You need to modify this(add multiple ace's) to add different groups, add everyone etc..

访问部分来源

这篇关于Powershell - 调用 WmiMethod 以远程创建具有完全控制权限的共享文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆