您好,登錄后才能下訂單哦!
建立文本文檔另存為csv文件,注意編碼格式,否則導入后是亂碼
使用powellshell命令導入
Import-Csv -Path E:\users.csv | foreach { new-aduser -name $_.name -SamAccountName $_.samaccountname -GivenName $_.givenname -Surname $_.surname -DisplayName $_.displayname -Path $_.path -UserPrincipalName $_.userprincipalname -AccountPassword (ConvertTo-SecureString -string $_.accountpassword -AsPlainText -Force ) -Enabled $true -ChangePasswordAtLogon $false }
3.查看建立的用戶
其他:
導出用戶的命令
第一步,先獲取AD上所有的OU 命令:Get-ADOrganizationalUnit -Filter 'Name -like "*"'
第二部,根據OU獲取用戶 命令:
Get-ADuser -searchbase 'OU=IT,DC=dareway,DC=com' -filter 'name -Like "*" ' -Properties * | Export-Csv c:\sharepointinfo.csv -enconding utf8
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
name,SamAccountName,GivenName,Surname,DisplayName,Department,UserPrincipalName,City,Office,StreetAddress,State,PostalCode,Title,Company,OfficePhone,HomePhone,MobilePhone,emailaddress
-------------------------------------------------------------------------------------------------------------------------------------------------------
獲取用戶信息中所需要的字段:
Get-ADuser -searchbase 'OU=IT,DC=dareway,DC=com' -filter 'name -Like "*" ' -Properties name,SamAccountName,GivenName,Surname,DisplayName,Department,UserPrincipalName,City,Office,StreetAddress,State,PostalCode,Title,Company,OfficePhone,HomePhone,MobilePhone,emailaddress | Export-Csv c:\sharepointinfo.csv -enconding utf8
導入用戶的命令
將CSV文件用記事本打開,并另存為Unicode編碼
PS C:\Users\Administrator\Desktop> Import-Csv "e:\file.csv" | foreach-object {New-ADUser -Path "ou=IT,dc=dareway,dc=cn"
-Name $_.name -SamAccountName $_.SamAccountName -GivenName $_.GivenName -Surname $_.Surname -DisplayName $_.DisplayName
-Department $_.Department -UserPrincipalName $_.UserPrincipalName -City $_.City -Office $_.Office -StreetAddress $_.Stre
etAddress -State $_.State -PostalCode $_.PostalCode -Title $_.Title -Company $_.Company -OfficePhone $_.OfficePhone -Hom
ePhone $_.HomePhone -MobilePhone $_.MobilePhone -emailaddress $_.emailaddress -AccountPassword (ConvertTo-SecureString "
Dareway@2018" -AsPlainText -force) -enabled $true -ChangePasswordAtLogon $true -PasswordNeverExpires $false -Passthru}
----------------------------------------------------------------------------------------------------------------------------------------------------
隨機生成初始密碼
Import-Csv "e:\file.csv" | foreach-object {New-ADUser -Path "ou=IT,dc=dareway,dc=cn" -Name $_.name -SamAccountName $_.SamAccountName -GivenName $_.GivenName -Surname $_.Surname -DisplayName $_.DisplayName
-Department $_.Department -UserPrincipalName $_.UserPrincipalName -City $_.City -Office $_.Office -StreetAddress $_.Stre
etAddress -State $_.State -PostalCode $_.PostalCode -Title $_.Title -Company $_.Company -OfficePhone $_.OfficePhone -Hom
ePhone $_.HomePhone -MobilePhone $_.MobilePhone -emailaddress $_.emailaddress -AccountPassword (ConvertTo-SecureString $_.password -AsPlainText -force) -enabled $true -ChangePasswordAtLogon $False -PasswordNeverExpires $false -Passthru}
----------------------------------------------------------------------------------------------------------------------------------------------------
獲取OU Beijing(包含子OU)下所有的user類型賬戶
get-user –OrganizationalUnit IT | where-object{$_.RecipientType –eq “User”}
批量啟用用戶
get-user –OrganizationalUnit IT | where-object{$_.RecipientType –eq “User”} | Enable-Mailbox –Database “Mailbox Database 0839106375” | get-mailbox | select name,windowsemailaddress,database
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。