PowerShell的chmod函数

Nar*_*rek 10 shell powershell chmod windows-7

我正在四处寻找了解如何在Windows 7 Power Shell上chmod(更改文件的权限)文件.所以我发现了不同的(因为我习惯于简单的chmod命令,因为我习惯了简单的chmod命令)代码片段,并且想知道将有线命令包装在chmod函数中并将其写入Power Shell的$ profile文件中是不是很简单.我想这就是许多ex-linux shell,但是现在的power shell用户想拥有更改文件的权限.

我是Power Shell的新手.请帮我解释一下代码.

JPB*_*anc 6

以下是使用ACL和ACE的本机方式示例.你必须建立自己的功能.

# Get the Access Control List from the file
# Be careful $acl is more a security descriptor with more information than ACL
$acl = Get-Acl "c:\temp\test.txt"


# Show here how to refer to useful enumerate values (see MSDN)
$Right = [System.Security.AccessControl.FileSystemRights]::FullControl
$Control = [System.Security.AccessControl.AccessControlType]::Allow

# Build the Access Control Entry ACE 
# Be careful you need to replace "everybody" by the user or group you want to add rights to
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule ("everybody", $Right, $Control)

# Add ACE to ACL
$acl.AddAccessRule($ace)

# Put ACL to the file
Set-Acl "c:\temp\test.txt" $acl
(Get-Acl "c:\temp\test.txt").access
Read-Host "--------- Test Here --------------"

# Remove ACE from ACL
$acl.RemoveAccessRule($ace)
Set-Acl "c:\temp\test.txt" $acl
(Get-Acl "c:\temp\test.txt").access
Run Code Online (Sandbox Code Playgroud)