Solved

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

Posted on 2013-01-08
4
318 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

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

920 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

16 Experts available now in Live!

Get 1:1 Help Now