【发布时间】:2019-04-02 15:25:04
【问题描述】:
我正在尝试使用 CSV 导入来创建批量用户,但它还可以创建用户的主文件夹和配置文件文件夹,但同时设置权限。
我在网上找到了很多有用的信息,我只是不知道如何使语法与我已经拥有的东西一起工作,这让我花了很长时间才明白。
到目前为止,这是我在域控制器上创建帐户然后将它们与 O365 同步的脚本。我们在同时创建大量用户时使用 csv:
Import-Csv "C:\blablabla\filename.csv" | ForEach-Object {
New-ADUser -Name $_.Name `
-GivenName $_."GivenName" `
-Surname $_."Surname" `
-DisplayName $_."DisplayName" `
-SamAccountName $_."samAccountName" `
-UserPrincipalName $_."UserPrincipalName" `
-Path $_."Path" `
-AccountPassword (ConvertTo-SecureString “Pa$$w0rd” -AsPlainText -force) -Enabled $true `
-EmailAddress $_."EmailAddress" `
-ProfilePath $_."ProfilePath" `
-HomeDrive $_."HomeDrive" `
-HomeDirectory $_."HomeDirectory" `
-ScriptPath $_."ScriptPath" `
-Server $_."Server" `
-OtherAttributes @{ProxyAddresses= $_."ProxyAddresses"} `
}
Start-ADSyncSyncCycle -PolicyType Initial
所有值都指向 excel 文件中的列,这些列会根据用户的名字和姓氏自动完成。
我知道我应该创建 home 和 profile 文件夹并设置权限,例如,我只是不知道如何使语法与我已有的语法一起工作?
到目前为止,仅在 AD 中正确设置了值,但没有创建文件夹,也没有应用权限。
我想我可以添加一个其他命令来创建一个新文件夹,但我不知道如何将它附加到 foreach 命令中?
New-Item -ItemType Directory -Path \\dc\userdata
$ACL = (Get-ACL -Path $HomeDirectory)
$FullControlAccessRule = (New-Object System.Security.AccessControl.FileSystemAccessRule([System.Security.Principal.NTAccount]"hcc.local\$UserName","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))
$ACL.AddAccessRule($FullControlAccessRule)
Set-ACL -Path $HomeDirectory $ACL
任何帮助将不胜感激。
谢谢。
所以,按照 NAS 的说法,然后是这样的
?
-OtherAttributes @{ProxyAddresses= $_."ProxyAddresses"}
New-Item -ItemType Directory -Path $_.HomeDirectory
New-Item -ItemType Directory -Path $_.ProfilePath
$ACL = (Get-ACL -Path $_.HomeDirectory)
$FullControlAccessRule = (New-Object System.Security.AccessControl.FileSystemAccessRule(
[System.Security.Principal.NTAccount]"hcc.local\$($_.samAccountName)",
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))
$ACL.AddAccessRule($FullControlAccessRule)
Set-ACL -Path $_.HomeDirectory $ACL
$ACL = (Get-ACL -Path $_.ProfilePath)
$FullControlAccessRule = (New-Object System.Security.AccessControl.FileSystemAccessRule(
[System.Security.Principal.NTAccount]"hcc.local\$($_.samAccountName)",
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))
$ACL.AddAccessRule($FullControlAccessRule)
Set-ACL -Path $_.ProfilePath $ACL
【问题讨论】:
标签: windows powershell csv azure-active-directory