标签:serv-u 背景 中断 效率 ftp group scope security 注意
一、背景因管理需要计划将现有的serv-u服务改成ad+iis+ftp+ntfs架构,所以需要在ad中新建对应群组并添加用户。
为提高效率减少重复工作,编写一个批量新增群组及添加用户脚本,以下为测试环境。
=INDEX(A:A,SMALL(IF($B$2:$B$200="Sam",ROW($2:$200),4^8),ROW(A1)))&""
Import-Module ActiveDirectory
$ngs=Import-Csv C:\Data\ngs.csv
$nus=Import-Csv C:\Data\nus.csv
foreach ($ng in $ngs) {
New-ADGroup -Name $ng.name -SamAccountName $ng.name -GroupCategory $ng.GroupCategory -GroupScope $ng.Groupscope -Path $ng.path -PassThru
Get-ADGroup -Identity $ng.name | Set-ADGroup -Replace @{info=$ng.info}
Add-ADGroupMember -Identity $ng.name -Members ($nus.($ng.name) | Where-Object {$_ -ne ‘‘} ) -PassThru
}
name,path,groupcategory,groupscope,info
ftp-ops-w,"OU=FTP,OU=Group,DC=lxy,DC=lin",Security,Global,"DRI:xx,TEL:xx"
ftp-ops-r,"OU=FTP,OU=Group,DC=lxy,DC=lin",Security,Global,"DRI:xx,TEL:xx"
ftp-dba-w,"OU=FTP,OU=Group,DC=lxy,DC=lin",Security,Global,"DRI:xx,TEL:xx"
ftp-dba-r,"OU=FTP,OU=Group,DC=lxy,DC=lin",Security,Global,"DRI:xx,TEL:xx"
ftp-ops-w,ftp-ops-r,ftp-dba-w,ftp-dba-r
user01,user02,user03,user04
user05,,user06,user07
user08,,user09,
Import-Module ActiveDirectory
foreach ( $num in 1..10 ) {
$user=‘USER‘+$num
New-ADUser $user -Path "OU=Test,DC=iku,DC=lxy" -Enabled:$true -AccountPassword(ConvertTo-SecureString "lxy1989." -AsPlainText -Force)
}
$ngs=Import-Csv C:\Data\ngs.csv
$nus=Import-Csv C:\Data\nus.csv
foreach ($ng in $ngs) {
New-ADGroup -Name $ng.name -SamAccountName $ng.name -GroupCategory $ng.GroupCategory -GroupScope $ng.Groupscope -Path $ng.path -PassThru
Get-ADGroup -Identity $ng.name | Set-ADGroup -Replace @{info=$ng.info}
}
foreach ($ng in $ngs) {
Add-ADGroupMember -Identity $ng.name -Members ($nus.($ng.name) | Where-Object {$_ -ne ‘‘} ) -PassThru
}
PS C:\Users\Administrator> ($nus.‘ftp-dba-r‘ | Where-Object {$_ -ne ‘‘}).count
3
---nu.csv
ftp-ops-w,ftp-ops-r,ftp-dba-w,ftp-dba-r
user1,user2,user3,user4,
user5,,user6,user7,
user8,,user9,,
---
PS C:\> ($nus.‘ftp-dba-r‘ | Where-Object {$_ -ne ‘‘}).count
2
foreach ($ng in $ngs) {
Get-ADGroupMember -Identity $ng.name | select @{name=‘group‘;expression={$ng.name}},@{name=‘name‘;expression={$_.name}}
}
group name
----- ----
ftp-ops-w USER1
ftp-ops-w USER5
ftp-ops-w USER8
ftp-ops-r USER2
ftp-dba-w USER3
ftp-dba-w USER6
ftp-dba-w USER9
ftp-dba-r USER4
ftp-dba-r USER7
foreach ($ng in $ngs) {
Remove-ADGroupMember -Identity $ng.name -Members (Get-ADGroupMember -Identity $ng.name)
}
标签:serv-u 背景 中断 效率 ftp group scope security 注意
原文地址:http://blog.51cto.com/linxy/2129564