在我的场景中,我必须阅读机器的Windows组。我只需要为某些Windows组的文件夹授予写入权限。
我需要在Powershell脚本中实现它。
答案 0 :(得分:0)
您好您可以使用以下脚本获取Windows机组列表,我猜您需要管理员组中的用户,下面的脚本将列出管理员组中的成员。
$compname = hostname
$computer = [ADSI]("WinNT://" + $compname + ",computer")
$Group = $computer.psbase.children.find("Administrators")
$Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
并且它的输出将是下面的声音
Administrator
Domain Admins
获得所需的组后,您可以使用以下powershell cmdlet分配权限 在我的方案中我设置了对“C:\ Data \ Learning Products”的写权限,我的意思是“域管理员”的“学习产品”文件夹
$Acl = Get-Acl "C:\Data\Learning Products"
$Ar = New-Object system.security.accesscontrol.filesystemaccessrule("Domain Admins","Write","Allow")
$Acl.SetAccessRule($Ar)
Set-Acl "C:\Data\Learning Products" $Acl
设置权限后,您可以通过运行
进行验证Get-Acl "C:\Data\Learning Products" | ForEach-Object { $_.Access } | ft -Wrap
哪个wpuld确实显示“域管理员”现在具有对文件夹的写入权限
P
osh (0310) > Get-Acl "C:\Data\Learning Products" | ForEach-Object { $_.Access } | ft -Wrap
FileSystemRights AccessControlType IdentityReference IsInherited InheritanceFlags PropagationFlags
---------------- ----------------- ----------------- ----------- ---------------- ----------------
Write, Synchronize Allow GDNINDIA\Domain False None None
Admins
FullControl Allow BUILTIN\Administrat True None None
ors
ObjectInherit
FullControl Allow NT AUTHORITY\SYSTEM True None None
ReadAndExecute, Allow BUILTIN\Users True ContainerInherit, None
Synchronize ObjectInherit
Modify, Synchronize Allow NT AUTHORITY\Authen True None None
ticated Users