第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從 csv 導(dǎo)入數(shù)據(jù)并創(chuàng)建 Active Directory 用戶列表

從 csv 導(dǎo)入數(shù)據(jù)并創(chuàng)建 Active Directory 用戶列表

慕尼黑8549860 2023-07-11 10:46:37
嘿,所以我試圖在 python 中從 powershell 制作相同的腳本,但我無法正確執(zhí)行,也許你可以幫助我,所以腳本是這樣的:打開包含用戶信息的 csv 文件為 csv 文件中的每一行創(chuàng)建用戶csv 看起來像這樣:powershell 腳本工作正常,如下所示:# import moduleImport-Module ActiveDirectory# create new password$securedpassword = ConvertTo-SecureString "abc-123" -AsPlainText -Force#import csv$filepath = Read-Host -Prompt "please enter csv path"#import the file into a variable$users = Import-Csv $filepath# loop all rows to gather informationforeach ($user in $users) {# gather user information$fname = $user.'first name'$lname = $user.'last name'$oupath = $user.'ou'#creat new ad user from csv fileNew-ADUser -name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincipalName "$fname.$lname" -Path $oupath -AccountPassword $securedpassword -ChangePasswordAtLogon $true -Enabled $true# echo outputecho "account created for $fname $lname in $oupath"}在Python中是這樣的:#import csv and active directory moduleimport csvfrom pyad import *def createuserfromcsv():    #takes full file path for test: c:\newusers.csv    file = input('please type your file path + file: ')        data = open(file,encoding="utf-8")        csv_data = csv.reader(data)        data_lines = list(csv_data)    pyad.set_defaults(ldap_server="DC-01-Training.Udemy.training",username="Administrator",password="abc-123")    for line in data_lines[1:]:        user = line[0]    for line in data_lines[1:]:        oupath = line[2]ou = pyad.adcontainer.ADContainer.from_dn(oupath)new_user = pyad.aduser.ADUser.create(user,ou,password="abc-123")print(user)print(oupath)我怎樣才能解決這個(gè)問題 ?
查看完整描述

3 回答

?
忽然笑

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊

好吧,我成功了,無論有沒有功能都可以:


import csv

from pyad import *

def createuserfromcsv():

    #takes full file path

    file = input('please type your file path + file: ')

    data = open(file,encoding="utf-8")

    csv_data = csv.reader(data)

    data_lines = list(csv_data)

    #load admin information

    pyad.set_defaults(ldap_server="DC-01-Training.Udemy.training",username="Administrator",password="abc-123")


    for line in data_lines[1:]:

        user = line[0]

        oupath = line[2]

        ou = pyad.adcontainer.ADContainer.from_dn(oupath)

        pyad.aduser.ADUser.create(user,ou,password="abc-123")


查看完整回答
反對(duì) 回復(fù) 2023-07-11
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

# Step 1: Install the required python modules


!pip install pyad

!pip install pandas


# Step 2: Import the necessary modules in your script


import pyad

import pandas as pd


# Step 3: Connect to the AD server


ad_user = "user@example.com"

ad_password = "password"

ad_domain = "example.com"


pyad.set_defaults(username=ad_user, password=ad_password)

ad_server = pyad.adserver.ADServer.from_domain_name(ad_domain)


# Step 4: Read the CSV file into a Pandas DataFrame


df = pd.read_csv("records.csv")


# Step 5: Iterate over the rows of the DataFrame and create AD users


ou = "OU=Users,DC=example,DC=com"  # The distinguished name of the AD organizational unit where you want to create the users


for index, row in df.iterrows():

  first_name = row["first_name"]

  last_name = row["last_name"]

  email = row["email"]

  password = row["password"]

  

  # Create the AD user

  user = pyad.aduser.ADUser.create(name=f"{first_name} {last_name}", upn=email, password=password, ou=ou)

  

  # Set additional attributes for the user

  user.update_attribute("givenName", first_name)

  user.update_attribute("sn", last_name)

  user.update_attribute("mail", email)


# Step 6: Save the changes to the AD server


ad_server.commit()


print("Import completed successfully!")

該腳本執(zhí)行以下步驟:

  1. 使用 pip 命令安裝所需的 python 模塊 pyad 和 pandas。

  2. 導(dǎo)入 pyad 和 pandas 模塊。

  3. 使用提供的域名和憑據(jù)連接到 AD 服務(wù)器。pyad.set_defaults() 函數(shù)用于設(shè)置連接的默認(rèn)用戶名和密碼。pyad.adserver.ADServer.from_domain_name() 函數(shù)用于根據(jù)提供的域名創(chuàng)建 AD 服務(wù)器對(duì)象。

  4. 使用 pandas.read_csv() 函數(shù)將 CSV 文件讀入 Pandas DataFrame。

  5. 使用 df.iterrows() 函數(shù)迭代 DataFrame 的行。對(duì)于每一行,腳本提取相關(guān)列的值(例如名字、姓氏、電子郵件、密碼)并將它們存儲(chǔ)在變量中。

  6. 使用 pyad.aduser.ADUser.create() 方法創(chuàng)建新的 AD 用戶。name 參數(shù)指定用戶的全名,upn 參數(shù)指定用戶主體名稱(電子郵件地址),password 參數(shù)指定用戶的密碼。ou 參數(shù)指定要在其中創(chuàng)建用戶的 AD 組織單位的可分辨名稱。

  7. 使用 user.update_attribute() 為用戶設(shè)置附加屬性


查看完整回答
反對(duì) 回復(fù) 2023-07-11
?
SMILET

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

   # Step 1: Import the ActiveDirectory module and connect to the AD server

    

    Import-Module ActiveDirectory

    

    $ad_user = "user@example.com"

    $ad_password = "password" | ConvertTo-SecureString -AsPlainText -Force

    $ad_credential = New-Object System.Management.Automation.PSCredential -ArgumentList $ad_user, $ad_password

    $ad_domain = "example.com"

    

    Connect-AzureAD -Credential $ad_credential -TenantId $ad_domain

    

    # Step 2: Read the CSV file into a variable as an array of objects

    

    $records = Import-Csv -Path "records.csv"

    

    # Step 3: Iterate over the array of objects and create AD users

    

    foreach ($record in $records) {

      $first_name = $record.first_name

      $last_name = $record.last_name

      $email = $record.email

      $password = $record.password

      

      # Create the AD user

      New-AzureADUser -AccountEnabled $true -DisplayName "$first_name $last_name" -PasswordProfile @{ Password = $password; ForceChangePasswordNextSignIn = $false } -UserPrincipalName $email -GivenName $first_name -Surname $last_name -MailNickname $email

      

      # Set additional attributes for the user

      Set-AzureADUser -ObjectId (Get-AzureADUser -Filter "UserPrincipalName eq '$email'").ObjectId -MobilePhone $record.mobile_phone -StreetAddress $record.street_address -City $record.city -State $record.state -PostalCode $record.postal_code -Country $record.country

    }

    

    # Step 4: Save the changes to the AD server

    

    Save-AzureAD

    

    Write-Host "Import completed successfully!"

  1. 將腳本保存到擴(kuò)展名為 .ps1 的文件中,例如 Import-ADUsers.ps1。

  2. 修改腳本為以下變量設(shè)置適當(dāng)?shù)闹担?/p>

  3. $ou:這是您要在其中創(chuàng)建新用戶的組織單位 (OU) 的可分辨名稱 (DN)。

  4. $csvFile:這是包含要導(dǎo)入的用戶記錄的 CSV 文件的路徑。

  5. 確保 CSV 文件具有腳本中指定的適當(dāng)列。

  6. 打開 PowerShell 窗口并導(dǎo)航到保存腳本的目錄。

  7. 使用以下命令運(yùn)行腳本: .\Import-ADUsers.ps1 該腳本將讀取 CSV 文件,為文件中的每條記錄創(chuàng)建一個(gè)新的用戶對(duì)象,并為每個(gè)用戶設(shè)置指定的屬性。

    請(qǐng)注意,您需要在計(jì)算機(jī)上安裝 Active Directory 模塊,并且需要使用管理權(quán)限運(yùn)行腳本。



查看完整回答
反對(duì) 回復(fù) 2023-07-11
  • 3 回答
  • 0 關(guān)注
  • 206 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)