Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article runs through the process of deploying a single EXE application selectively to a group of user.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

825 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