2012-09-13 8 views
9

Windows 7 Power Shellでファイルをchmod(ファイルのアクセス権を変更する方法)を理解する方法を探していました。私は単純なchmodコマンドに慣れているため、コードスニペットとchmod関数でその有線コマンドをラップしてPower Shellの$ profileファイルに書き込むのは簡単ではないと思っています。私はこれが多くの元Linuxのシェルだと思いますが、パワーシェルのユーザーはファイルのパーミッションを変更したいと思っています。PowerShellのchmod関数

私はPower Shellを初めて使用しています。コードで私を助けてください。次の

+0

'Get-Help Set-ACL -full'を試したことがありますか? http://chrisfederico.wordpress.com/2008/02/01/setting-acl-on-a-file-or-directory-in-powershell/ –

答えて

5

ここでは、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 
1

ルック:

  • Set-Acl - ファイル属性を設定するための標準的なWindowsのツール -

  • attrib.exeGet-Help Set-Acl -Fullを実行します。 Powershellではなく、もちろんPowershellでも動作します。

  • icacls.exe - ACLを設定するための標準Windowsツール。 Powershellではなく、もちろんPowershellでも動作します。

出典:http://www.cs.wright.edu/~pmateti/Courses/233/Labs/Scripting/bashVsPowerShellTable.html だけchmod powershellのためのWeb検索を行います。