Solved

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

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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