直接上脚本(比较简单就不解释了):打开poweshell执行脚本策略powershell中执行set-executionpolicy remotesigned用法: 复制到txt改后缀为ps1 然后拖
直接上脚本(比较简单就不解释了):
打开poweshell执行脚本策略
powershell中执行
set-executionpolicy remotesigned
用法: 复制到txt改后缀为ps1 然后拖到powershell中执行
创建域用户组
##author: Firxiao##date:20160915##usage: create ad groupImport-Module ActiveDirectory##group lists$groups = @("group01""group02""group03") #loopforeach($group in $groups){##NEW-ADGroup –name “Finance” –groupscope Global –path “OU=Offices,DC=Contoso,DC=local”echo "create group $group"NEW-ADGroup –name “$group” –groupscope Global}
导出组用户到csv
##author: Firxiao##date:20160915##usage: export groups member to csv fileImport-Module ActiveDirectory##create path$path = "$(pwd)/Desktop/export"If(!(test-path $path)){New-Item -ItemType Directory -Force -Path $path}##group lists$groups = @("group01""group02""group03") #export loopforeach($group in $groups){echo "export ${group} to $path/${group}.csv"Get-ADGroupMember -identity "${group}" | select SamAccountName| Export-csv -path $path/${group}.csv -NoTypeInformation}
csv用户导入组
##author: Firxiao##date:20160915##usage: import csv groups member to groupImport-Module ActiveDirectory##create path$path = "$(pwd)/Desktop/export"If(!(test-path $path)){echo "Please make sure the csv dir is exits"}##group lists$groups = @("group01""group02""group03") #export loopforeach($group in $groups){echo "import $path/${group}.csv to ${group}" Import-CSV "$path/${group}.csv" | % { Add-ADGroupMember -Identity "${group}" -Member $_.SamAccountName} }