![]() |
Заполнение атрибутов в AD выборкой по таблице (аналог ВПР Excel).
Помогите создать аналог ВПР Excel в формате cmd
Найти в AD атрибут пользователя title сравнить со значением в таблице (формат таблицы csv) если совпадает со значением в первом столбце то записать его английский аналог в другой атрибут strmsExchExtensionCustomAttribute1 Таблица ##title=strmsExchExtensionCustomAttribute1 Системный администратор;System Administrator Повар;Cook |
Где я туплю, ошибка на Get-ADUser
$attribute = 'msExchExtensionCustomAttribute1' $file = Import-CSV "C:\Scripts\UpdateAttrib\Users.csv" #Loop through the data and get the user on the row FOREACH ($Account in $file){ #Find the AD User Object Get-ADUser -Filter {msExchExtensionCustomAttribute2 -eq $Account.0} -Properties Name,title,$attribute } 0,1 Авада,System Кадавра,Kadaura Вот этот код не срабатывает {msExchExtensionCustomAttribute2 -eq $Account.0} |
serraxer, делайте строго наоборот: вместо N запросов к базе данных AD — единожды получите список пользователей, затем проверяйте, есть ли очередной пользователь из него в ассоциативном массиве, полученном из содержимого текстового файла.
|
Прошу прощения а это как? Я пытаюсь получить список должностей (title).
Брал за основу рабочий скрипт который позволяет менять атрибуты из списка просто указав атрибут который надо поменять. Скрытый текст
#Created by Brad Held
#This script changes attributes in Active Directory, while I have tested this in my environment #I can not and will not take responsibility for anything that happens when running this script in your environment #Get the Attribute from the user $attribute = Read-Host "What is the attribute you want to modify?" #Where to save the original values we are about to change $out = "C:\Scripts\UpdateAttrib\Original.csv" #Load the data - First row in the csv should be 0,1 $list = Import-CSV C:\Scripts\UpdateAttrib\Users.csv #Loop through the data and get the user on the row FOREACH ($Account in $list){ #Find the AD User Object $User = Get-ADUser -identity $Account.0 -Properties Name,SamaccountName,$attribute #Save the users current information to file $User | FT Samaccountname,$attribute | Out-File $out -Append #Modify the current user based on the information from csv $User.$attribute = $Account.1 #Save that information back to the user account Set-ADUser -Instance $User } В нем выборка идет как я понял по -identity который потом сравнивается с csv, запрос Get-ADUser -identity $Account.0 Я поменял -identity на -Filter и полагал что теперь начнется сравнение с csv в котором все прописано. Кстати если я пишу конкретный title то все заменяется. |
serraxer, у меня сейчас нет AD, не на чем отлаживать.
Цитата:
|
Время: 22:45. |
Время: 22:45.
© OSzone.net 2001-