POwershell 更改文件权限
今天需要给某个网络共享的大文件重新配置一个权限。这个文件夹下面有很多乱七八糟的小文件,很多创建人甚至已经离开公司了。如果一个个地目录手动修改所有者权限,再打开继承关系,这样比较麻烦,这个时候自然是用脚本比较方便了。
#网上找的现成的高级方法来enable继承关系 function Set-NTFSInheritance { <# .SYNOPSIS Enable or Disable the NTFS permissions inheritance. .DESCRIPTION Enable or Disable the NTFS permissions inheritance on files and/or folders. .EXAMPLE $Folders = Get-Childitem -Path 'e:\homedirs' | Where-Object {$_.Attributes -eq 'Directory'} $Folders | foreach { $_ | Set-NTFSInheritance -Enable } .NOTES Author : Jeff Wouters Date : 8th of May 2014 #> [cmdletbinding(defaultparametersetname='Enable')] param ( [parameter(mandatory=$true,position=0,valuefrompipeline=$true,parametersetname='Enable')] [parameter(mandatory=$true,position=0,valuefrompipeline=$true,parametersetname='Disable')] $Path, [parameter(mandatory=$false,parametersetname='Enable')][switch]$Enable, [parameter(mandatory=$false,parametersetname='Disable')][switch]$Disable ) begin { } process { $ACL = get-acl $_.FullName switch ($PSCmdlet.ParameterSetName) { 'Enable' { $ACL.SetAcce***uleProtection($false,$false) } 'Disable' { $ACL.SetAcce***uleProtection($true,$true) } } try { $ACL | Set-Acl -Passthru } catch { $_.Exception } } end { } } #自己调用一下上面的方法,基本上就是三步走,第一个夺取所有权;第二打开继承关系;第三在最上面设置权限 function ChangePermission { [cmdletbinding(defaultparametersetname='Enable')] param ( [Parameter(Mandatory=$true)] [string] $path, [Parameter(Mandatory=$true)] [string] $group ) #Step 1: take over ownership takeown.exe /f $path /r /d Y #Step 2: enable inheritance for all subfolders $Folders = Get-Childitem -Path $path -Recurse $Folders | foreach { $_ | Set-NTFSInheritance -Enable } #Step3: setup NTFS Modify permission from the parent folder $perm2=':(OI)(CI)(M)' write-host $path -ForegroundColor Cyan icacls $path /grant "$($group)$perm2" } #最后调用函数即可 $parent="\\syd02\Creative TRACK\CLIENT FOLDERS\WESTPAC" Get-ChildItem $parent | foreach { $_.fullname ChangePermission -path $_.FullName -group "Sydney Track Creative" }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
分分钟一键部署Zabbix Server
为了方便把安装Zabbix的过程整理成自动化一键部署脚本,有兴趣可以参考,都是些基本的命令: #!/bin/bash #Zabbix一键部署脚本 #安装zabbix3.0.4,依赖php-5.6.25 src_home=`pwd` echo-n"正在配置iptables防火墙……" /etc/init.d/iptablessave>>/dev/null chkconfigiptablesoff if[$?-eq0];then echo-n"Iptables防火墙初始化完毕!" fi echo-n"正在关闭SELinux……" setenforce0>/dev/null2>&1 sed-i'/^SELINUX=/s/=.*/=disabled/'/etc/selinux/config if[$?-eq0];then echo-n"SELinux初始化完毕!" fi echo-n"正在安装nginxyum源……" yum-yinstallwget wgethttp://nginx.org/packages/centos/6/noarch/RPMS/nginx...
- 下一篇
Zabbix zabbix_get及Item总结
zabbix_get是什么? zabbix-get 是Zabbix 中的一个程序,用于zabbix-Server 到zabbix-agent 的数据获取,通常可以用来检测验证agent 的配置是否正确,类似nagios的./check_nt等监控工具。 zabbix_get作用? 1)Server端和Agent端测试数据 2)判断一些故障问题,或者获取指定数据。 zabbix_get格式: [root@loganalyzerbin]#./zabbix_get-h usage: zabbix_get-shost-name-or-IP[-pport-number][-IIP-address]-kitem-key zabbix_get-h zabbix_get-V GetdatafromZabbixagent. Generaloptions: -s--hosthost-name-or-IPSpecifyhostnameorIPaddressofahost -p--portport-numberSpecifyportnumberofagentrunningonthehost (default:...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS7设置SWAP分区,小内存服务器的救世主
- CentOS8安装Docker,最新的服务器搭配容器使用
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS7安装Docker,走上虚拟化容器引擎之路
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Windows10,CentOS7,CentOS8安装Nodejs环境