简述为员工创立个人文件夹的三种方法

需求:
为公司每个有域帐号的员工创立一个个人文件夹。
此文件夹权限为员工本人完全控制和管理员完全控制。
映射到员工的磁盘Z盘为驱动器

解决:
三种方式:
一,手动设置
在共享服务器D盘建立文件夹Personalsharefile
共享权限Everyon可编辑。共享名可以加$隐藏。图1

本地安全如图2

主要是关闭权限继承,domain user只应用到当前文件夹,不继承。

选定多个用户,然后配置配置主文件夹如下。图3。
\192.168.1.160\PersonalShareFile\%username%

点应用后会自动在PSF文件夹下简历对应用户名的文件夹。

权限如下图

然后客户端就能看到

二,Powershell全自动
来源及参考:https://gallery.technet.microsoft.com/scriptcenter/PowerShell-script-to-832e08ed

脚本内容:
$Domain = "kaedeleo.com"
$ADServer = "dc01"
#文件服务器名或IP
$searchbase = "ou=人事部,ou=天越公司,DC=kaedeleo,DC=com"
#OU区域
$ShareFolderPhysicalPath="D:\PersonalShareFile"
#本机文件夹路径
$ShareFolderNetworkPath="PersonalShareFile"
#共享名,后面可以加$隐藏
$homeDrive = "Z"
#映射的磁盘,可以随便写一个非磁盘名字的来删除映射,比如"abc"
$FilenameType="surname"
#创立的私人文件夹的名字,这里用的surname,姓;也可以用displayname之类的。
if(!(Test-Path $ShareFolderPhysicalPath))
{
New-Item -Path $ShareFolderPhysicalPath -type directory
icacls $ShareFolderPhysicalPath /inheritance:r /grant:r ‘administrators:(OI)(CI)F‘ ‘system:(OI)(CI)F‘ ‘creator owner:(CI)(OI)F‘
}
New-SmbShare -name $ShareFolderNetworkPath -Path $ShareFolderPhysicalPath -FullAccess everyone
Import-Module ActiveDirectory
$ADUsers = Get-ADUser -server $ADServer -Filter -searchbase $searchbase -Properties
ForEach ($ADUser in $ADUsers)
{
New-Item -ItemType Directory -Path "\$ADServer\$ShareFolderNetworkPath\$($ADUser.$FilenameType)"
$UsersAm = "$Domain\$($ADUser.sAMAccountname)"
$FileSystemAccessRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
$InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]::"ContainerInherit", "ObjectInherit"
$PropagationFlags = [System.Security.AccessControl.PropagationFlags]::None
$AccessControl =[System.Security.AccessControl.AccessControlType]::Allow
$NewAccessrule = New-Object System.Security.AccessControl.FileSystemAccessRule `
($UsersAm, $FileSystemAccessRights, $InheritanceFlags, $PropagationFlags, $AccessControl)
$userfolder = "\$ADServer\$ShareFolderNetworkPath\$($ADUser.$FilenameType)"
$currentACL = Get-ACL -path $userfolder
$currentACL.SetAccessRule($NewAccessrule)
Set-ACL -path $userfolder -AclObject $currentACL
$homeDirectory = "\$ADServer\$ShareFolderNetworkPath\$($ADUser.$FilenameType)"
Set-ADUser -server $ADServer -Identity $ADUser.sAMAccountname -Replace @{HomeDirectory=$homeDirectory}
Set-ADUser -server $ADServer -Identity $ADUser.sAMAccountname -Replace @{HomeDrive=$homeDrive}
}
pause

效果是
在DC01 的D盘建立PSF文件夹
共享设置权限为everyone完全
本地权限设置为一手动设置内的一致
在PSF建立OU范围内的以每个用户的姓为文件名的文件夹并映射到用户主文件夹
效果与手动是一致的
可以自定义更多东西,但是用户那个属性里一定要有东西,不然会变得很奇怪。。

三,Powershell+登录脚本
Powershell:
$domainname="kaedeleo.com"
$ShareFolderPhysicalPath="D:\PersonalShareFile"
$ShareFolderNetworkPath="PersonalShareFile"
if(!(Test-Path $ShareFolderPhysicalPath))
{
New-Item -Path $ShareFolderPhysicalPath -type directory
icacls $ShareFolderPhysicalPath /inheritance:r /grant:r ‘administrators:(OI)(CI)F‘ ‘system:(OI)(CI)F‘ "$domainname\domain users:F" ‘creator owner:(CI)(OI)F‘
}
New-SmbShare -name $ShareFolderNetworkPath -Path $ShareFolderPhysicalPath -FullAccess everyone

从上面的脚本中取一部分。
建立文件夹和共享和本地权限。

然后用组策略的登陆脚本来创建文件夹和影射磁盘驱动器。
@echo off
set patha=\192.168.1.160\PersonalShareFile
if exist "%patha%\%username%" goto netuse
md "%patha%\%username%"
:netuse
net use | find "X:" >nul
if errorlevel 1 net use X: "%patha%\%username%"
pause

这样做的好处是,只要做一个全局组策略的,每次新员工登陆就会自动创建。不需要像前两个再手动设置或者运行一下。

进阶需求:
权限枚举
文件屏蔽
配额管理
邮箱报警

原文地址:http://blog.51cto.com/xifanliang/2106488

时间: 2024-08-07 03:11:06

简述为员工创立个人文件夹的三种方法的相关文章

自动创建文件夹的两种方法

自动创建文件夹的两种方法 1.CreateDictionary() CreateDirectory(myPath, 0); //在临时文件夹中创建本应用的文件夹 原型为:BOOL WINAPI CreateDirectory(__in  LPCTSTR lpPathName, __in LPSECURITY_ATTRIBUTES lpSecurityAttributes); 其中lpPathName是要创建的目录的路径,第2个涉及安全性问题 传NULL就好了 例如: char path[MAX_

Linux下快速清空文件内容的三种方法

Linux下快速清空文件内容的三种方法在Linux环境中,我们如果想快速清空一个文件或者log的内容: 1.#echo "" > test.txt(文件大小被截为1字节) 2.# > test.txt(文件大小被截为0字节) 3.#cat /dev/null > /home/test.txt(文件大小被截为0字节)————————————————版权声明:本文为CSDN博主「贾维斯博客」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声

php读取文件内容的三种方法

<?php //**************第一种读取方式***************************** 代码如下: header("content-type:text/html;charset=utf-8"); //文件路径 $file_path = "text.txt"; //判断是否有这个文件 if (file_exists($file_path)) { if ($fp = fopen($file_path, "a+"))

前端下载excel文件功能的三种方法

1 从后端接收json数据,前端处理生成excel下载 JsonExportExcel的github地址:https://github.com/cuikangjie/JsonExportExcel 这种方式比较适用于该数据需要能够导出下载并且同时要展现在页面的场景 2 通过form表单接收文件 如果后端已经处理成了excel,就不需要前端在处理生成,但是Ajax能够返回的数据格式只能为html,script,json,xml,不能直接接受excel文件,如果你直接通过ajax去获取文件就会报错.

ASP.net 判断上传文件类型的三种方法

一. 安全性比较低,把文本文件1.txt改成1.jpg照样可以上传,但其实现方法容易理解,实现也简单,所以网上很多还是采取这种方法. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Boolean fileOk = false;           string path = Server.MapPath("~/images

Java追加文件内容的三种方法

import <a href="http://lib.csdn.net/base/17" class='replace_word' title="Java EE知识库" target='_blank' style='color:#df3434; font-weight:bold;'>Java</a>.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream;

2、python逐行读取文件内容的三种方法

方法一: 复制代码代码如下: f = open("foo.txt") # 返回一个文件对象 line = f.readline() # 调用文件的 readline()方法 while line: print line, # 后面跟 ',' 将忽略换行符 # print(line, end = '') # 在 Python 3 中使用 line = f.readline() f.close() 方法二: 复制代码代码如下: for line in open("foo.txt&

python逐行读取文件内容的三种方法

方法一: f = open("foo.txt") # 返回一个文件对象 line = f.readline() # 调用文件的 readline()方法 while line: print line, # 后面跟 ',' 将忽略换行符 # print(line, end = '') # 在 Python 3中使用 line = f.readline() f.close() 方法二: for line in open("foo.txt"): print line, 方

python 如何找到某一目录下的文件类型(三种方法)

#!/usr/bin/env python 1 import glob 2 import os 3 os.chdir(“./”) 4 for file in glob.glob(“*.py”): 5 print file print “#######Another One##########” import osfor file in os.listdir(“./”): if file.endswith(“.py”): print file print “#######Another Two##