Solved

How to read/query Active Directory in real time without being read by a variable

Posted on 2013-01-08
4
317 Views
Last Modified: 2013-01-09
If i query AD and add all the information on variable $ad, the contents are in memory and not a realtime stage.

So, if i do modify properties of an AD user, all those modification are done through $ad via Set-ADUser.

In every property change i prompt "are you sure about the change of this for that?" and give the opportunity of changing more properties of the same user by asking for it.

But, if i typed a wrong last name and the time comes to ask "are you sure about the change of this for that" $ad has the old value not the new value. Is there anyway to query AD in real time?

<code>
$ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=ou,DC=domain,DC=com" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
</code>

Thanks for your help,
0
Comment
Question by:namerg
  • 2
4 Comments
 
LVL 39

Assisted Solution

by:footech
footech earned 250 total points
ID: 38757200
This question is a little hard to understand outside the context of your question at
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27987781.html
so here's a link back to it.

So in your script you've made a query for all users in AD and stored them to a variable.  As you work through each of them with a foreach loop, anytime you need to make another query it's pretty much the same command that you have above, and filter/match it with the current object being handled by the foreach loop.
Get-ADUser -filter {samAccountName -like "$AD_User.samAccountName"} -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=ou,DC=domain,DC=com"

Open in new window

May have to use $($AD_User.samAccountName) in place of $AD_User.samAccountName in the above.
0
 

Author Comment

by:namerg
ID: 38757212
Yes, @footech I know is little hard to understand. Working on the flow chart.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
ID: 38758147
You can either do
$File = Import-Csv "c:\scripts\ad\temp\FILE.csv" -header sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber

Foreach ($User in $FILE){
$Ad = Get-ADUser -Filter {Surname -eq $User.Surname} -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=COMPANY,DC=COMPANYcolo,DC=pvt" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
 	$Ad | % {
"Your Script to modify"
 }
}

Open in new window

Or
$File = Import-Csv "c:\scripts\ad\temp\FILE.csv" -header sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
$Ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=COMPANY,DC=COMPANYcolo,DC=pvt" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber

Foreach ($User in $FILE){
	$Ad | ? {$_.sn -eq $User.sn} | % {
"Your Script to modify"
 }
}

Open in new window

0
 

Author Comment

by:namerg
ID: 38759658
@Subsun,
Can you check the flowchart diagram in the bottom on this question http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27987781.html

Let me know what you think.. thanks
0

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now