Hi,
Me again , yes yes i know , now you are going to ask me ,,"Aman" what is your task for the day",, ok ok telling you..Today my manager told me to find all active directory users which don't have the CITY field set or those users whose CITY field is blank in there user properties.
I know that Active Directory Module has a Cmdlet to find users which is : Get-ADUser
Let's Start.
Make sure you have "RSAT" installed on you laptop.
Now Import the Active Directory module.
Import-Module ActiveDirectory
..
ok, Module is imported,
To find all users in AD we need to user -Filter * and to get there all properties we need to use -Properties * parameters.
Get-ADUser -Filter * -Properties *
but our target it to find CITY field which is blank., let's use Where-Object cmdlet to do this.
In this command we are asking powershell to Find all users with all of there properties and then then show is only those users whose CITY property is $null or blank.
Get-ADUser -Filter * -Properties * | Where-Object { $_.City -eq $null}
this is showing us huge amount of data.
Lets just select names of the users only.
Get-ADUser -Filter * -Properties * | Where-Object { $_.City -eq $null} | Select Name
Wow !! i have the names of all users whose City filed in blank.. i can export it to CSV files and sent to my Manager :)
Thanks for reading
Thanks!
Aman Dhally
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.