Csv 为使用powershell的ADDS 2008 R2上的用户设置HomeDirectory参数

Csv 为使用powershell的ADDS 2008 R2上的用户设置HomeDirectory参数,csv,powershell,scripting,active-directory,Csv,Powershell,Scripting,Active Directory,我正在尝试将“HomeDirectory”参数设置为给定.csv文件的用户列表。我使用的是特雷弗·沙利文(Trevor Sullivan)创建的修改脚本,并在以下帖子中列出: 这是我的剧本: $UserList = Import-Csv -Path c:\scripts\Users2.csv; foreach ($User in $UserList) { $Account = Get-ADUser -Identity $User.SamAccountName $Account.Home

我正在尝试将“HomeDirectory”参数设置为给定.csv文件的用户列表。我使用的是特雷弗·沙利文(Trevor Sullivan)创建的修改脚本,并在以下帖子中列出:

这是我的剧本:

$UserList = Import-Csv -Path c:\scripts\Users2.csv;  
foreach ($User in $UserList)  {

$Account = Get-ADUser -Identity $User.SamAccountName
$Account.HomeDirectory = '\\adminclusterfs\homedir\{0}' -f $Account.SamAccountName;
$Account.homeDrive = "O:"
Set-ADUser -Instance $Account -PassThru
}
剧本几乎很好。。。.csv文件上的每个用户都正确设置了HomeDirectory和HomeDrive参数,但文件服务器上没有创建文件夹。

当我手动设置这些参数时,也会创建文件夹

有人解决了这个问题


我真的很感谢你的帮助

如果您的帐户有权访问,广告用户和计算机将为您创建文件夹。这是在您的计算机上运行的用户和计算机程序的功能,而不是AD服务器本身的功能


您必须在脚本中添加代码来创建文件夹。

这里是我为设置HomeDirectory和HomeDrive参数、创建文件夹并为其分配访问权限而编写的完整脚本。感谢Trevor Sullivan和Sean Kearney的帖子

# Import the user data from CSV
$UserList = Import-Csv -Path c:\scripts\Users2.csv;

# For each user ...
foreach ($User in $UserList) {
# Get the user's AD account
$Account = Get-ADUser -Identity $User.SamAccountName

# Dynamically declare their home directory path in a String
$Account.HomeDirectory = '\\fileserver\homedir\{0}' -f $Account.SamAccountName;
$Account.homeDrive = "O:"

# Set their home directory and home drive letter in Active Directory
Set-ADUser -Instance $Account

# Create the folder on the root of the Homedirectory Share
NEW-ITEM –path $Account.HomeDirectory -type directory -force 

# Set parameters for Access rule
$IdentityReference = 'Domain\' + $Account.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"

# Build Access Rule from parameters
$AccessRule = NEW-OBJECT System.Security.AccessControl.FileSystemAccessRule -argumentlist ($IdentityReference,$FileSystemAccessRights,$InheritanceFlags,$PropagationFlags,$AccessControl)

# Get current Access Rule from Home Folder for User
$HomeFolderACL = GET-ACL $Account.HomeDirectory
$HomeFolderACL.AddAccessRule($AccessRule)

# Set Access rule to the folder
SET-ACL –path $Account.HomeDirectory -AclObject $HomeFolderACL
}

请不要使用链接。相反,复制一个最小但足够的代码摘要。谢谢Gabriel,我找到了一些文章,解释了创建文件夹和正确分配访问权限的所有过程。[连结]