Demo entry 6633857

ps

   

Submitted by lu on Aug 07, 2017 at 05:43
Language: PowerShell. Code size: 1.8 kB.

----------------------------------------------------------------------------------------
创建OU,组和用户
----------------------------------------------------------------------------------------
ImportSystemModules

$userpassword=(ConvertTo-SecureString -AsPlainText "P@ssw0rd0217" -Force)

ipcsv 'C:\ps\Create-Ou.txt' | %{New-ADOrganizationalUnit -Name $_.name -path $_.path} 

ipcsv 'C:\ps\Create-Group.txt' | %{New-ADGroup -Name $_.name -SamAccountName $_.SamAccountName -Path $_.path -GroupCategory Security -GroupScope DomainLocal} 

ipcsv 'C:\ps\Create-Users.txt'| %{New-ADUser -Name $_.name -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -GivenName $_.GivenName -Surname $_.Surname -DisplayName $_.DisplayName -Path $_.path -AccountPassword $userpassword}

---------------------------------------------------------------------------------------
启用账号
----------------------------------------------------------------------------------------
Get-ADUser -Filter * -SearchBase "OU=立白集团,DC=demo,DC=com" | Enable-ADAccount  

Get-ADUser -Filter * -SearchBase "OU=销售部,OU=立白集团,DC=demo,DC=com" | %{Add-ADGroupMember "销售部" -Members $_.SamAccountName} 

Get-ADUser -Filter * -SearchBase "OU=人事部,OU=demo,DC=demo,DC=com" | %{Add-ADGroupMember "人事部" -Members $_.SamAccountName} 

Get-ADUser -Filter * -SearchBase "OU=IT部,OU=立白集团,DC=demo,DC=com" | %{Add-ADGroupMember "IT部" -Members $_.SamAccountName}

Get-ADUser -Filter * -SearchBase "OU=基础网络组,OU=IT部,OU=立白集团,DC=demo,DC=com" | %{Add-ADGroupMember "IT部" -Members $_.SamAccountName}

Get-ADUser -Filter * -SearchBase "OU=终端支持组组,OU=IT部,OU=立白集团,DC=demo,DC=com" | %{Add-ADGroupMember "IT部" -Members $_.SamAccountName}

Get-ADUser -Filter * -SearchBase "OU=服务支持组,OU=IT部,OU=立白集团,DC=demo,DC=com" | %{Add-ADGroupMember "IT部" -Members $_.SamAccountName}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).