SAM IT
asked on
Need to script to pull out the report from Active directory
Hello Frnz,
Need to script to pull out the report from Active directory , Script has to pull out only users created & disabled from last 8 days with below mentioned fields, any help please
NTAccountName ParentContainer Email AccountIsDisabled Manager SamAccountName DN UserPrincipalName CreationDate co City Office PhoneNumber
Need to script to pull out the report from Active directory , Script has to pull out only users created & disabled from last 8 days with below mentioned fields, any help please
NTAccountName ParentContainer Email AccountIsDisabled Manager SamAccountName DN UserPrincipalName CreationDate co City Office PhoneNumber
ASKER
I am sorry, this wont works for my requirement , But I got the similar script for my requirement below mentioned one I need to add the fields like NTAccountName ParentContainer Email AccountIsDisabled Manager SamAccountName DN UserPrincipalName CreationDate co City Office PhoneNumber
Script:
Get-ADUser -Filter * -Properties Modified | Where {$_.Modified -ge $(Get-Date).AddDays(-1)}
Script:
Get-ADUser -Filter * -Properties Modified | Where {$_.Modified -ge $(Get-Date).AddDays(-1)}
There is no AD attribute where the "Disabled" date is stored; this will only be traced if you have AD auditing enabled, and then you'd have to retrieve it from the security event log.
Modified/WhenChanged includes any changes, which includes attributes like Lastlogon which will be changed without an administrator doing anything manually.
You can obviously pipe the results further to Sort-Object and/or Export-Csv as required.
Modified/WhenChanged includes any changes, which includes attributes like Lastlogon which will be changed without an administrator doing anything manually.
You can obviously pipe the results further to Sort-Object and/or Export-Csv as required.
$FilterDate = (Get-Date).AddDays(-8).Date
Get-ADUser -Filter {(whenCreated -ge $FilterDate) -or (whenChanged -ge $FilterDate)} -Property UserPrincipalName, Enabled, Mail, l, physicalDeliveryOfficeName, telephoneNumber, co, Manager, whenCreated, whenChanged |
Select-Object -Property SamAccountName, UserPrincipalName, Enabled, WhenCreated, WhenChanged, Mail, @{n='City'; e={$_.l}}, physicalDeliveryOfficeName, TelephoneNumber, @{n='Country'; e={$_.co}}, Manager, DistinguishedName, @{n='ParentContainer'; e={($_.DistinguishedName -split '(?<!\\),', 2)[1]}}
ASKER
Perfectly worked, If I add NTAccountName in to this script, its given error, please assist
There is no attribute "NTAccountName"; SamAccountName (the pre-Windows-2000 logon name) is probably what you mean, and that's already included.
ASKER
please see the below mentioned the difference between NTAccountName & SamAccountName
NTAccountName: Domain\username
SamAccountName : username
NTAccountName: Domain\username
SamAccountName : username
$FilterDate = (Get-Date).AddDays(-8).Date
$NetBIOSDomain = (Get-ADDomain).NetBIOSName
Get-ADUser -Filter {(whenCreated -ge $FilterDate) -or (whenChanged -ge $FilterDate)} -Property UserPrincipalName, Enabled, Mail, l, physicalDeliveryOfficeName, telephoneNumber, co, Manager, whenCreated, whenChanged |
Select-Object -Property SamAccountName, @{n='NTAccountName'; e={"$($NetBIOSDomain)\$($_.SamAccountName)"}}, UserPrincipalName, Enabled, WhenCreated, WhenChanged, Mail, @{n='City'; e={$_.l}}, physicalDeliveryOfficeName, TelephoneNumber, @{n='Country'; e={$_.co}}, Manager, DistinguishedName, @{n='ParentContainer'; e={($_.DistinguishedName -split '(?<!\\),', 2)[1]}}
ASKER
Thanks for excellent script and Would like to know that I want to enance my skills in powershell please suggest is there any tranings to imporve the skill set. Thanks in advance
Can't recommend any, sorry; was all "learning by doing" for me.
ASKER
Script is pulling out the created users in 2006, need users created in last 8 days with below attribute
______________________---- ---------- ---------- ---------- ---------- ---------- -
$FilterDate = (Get-Date).AddDays(-8).Dat e
$NetBIOSDomain = (Get-ADDomain).NetBIOSName
Get-ADUser -Filter {(whenCreated -ge $FilterDate) -or (whenChanged -ge $FilterDate)} -Property UserPrincipalName, Enabled, Mail, l, physicalDeliveryOfficeName , telephoneNumber, co, Manager, whenCreated, whenChanged |
Select-Object -Property SamAccountName, @{n='NTAccountName'; e={"$($NetBIOSDomain)\$($_ .SamAccoun tName)"}}, UserPrincipalName, Enabled, WhenCreated, WhenChanged, Mail, @{n='City'; e={$_.l}}, physicalDeliveryOfficeName , TelephoneNumber, @{n='Country'; e={$_.co}}, Manager, DistinguishedName, @{n='ParentContainer'; e={($_.DistinguishedName -split '(?<!\\),', 2)[1]}} | Export-Csv C:\Users\nsumanth\Desktop\ testnew.cs v
______________________----
$FilterDate = (Get-Date).AddDays(-8).Dat
$NetBIOSDomain = (Get-ADDomain).NetBIOSName
Get-ADUser -Filter {(whenCreated -ge $FilterDate) -or (whenChanged -ge $FilterDate)} -Property UserPrincipalName, Enabled, Mail, l, physicalDeliveryOfficeName
Select-Object -Property SamAccountName, @{n='NTAccountName'; e={"$($NetBIOSDomain)\$($_
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
whenChanged states if any Object is modified in the AD its is considered as whenChanged
Yes, that's what I said in https:#a42035589
You mentioned in https:#a42035580 "I got the similar script for my requirement below mentioned", with the reference to Modified/WhenChanged, so I added the whenChanged.
You mentioned in https:#a42035580 "I got the similar script for my requirement below mentioned", with the reference to Modified/WhenChanged, so I added the whenChanged.
ASKER
Best response....
Open in new window
That will pull more than you need but you can filter it by the created dates in excel :-)
P.S The best way to build this sort of script is to do a get-aduser "Your username" -properties * and then you can pick from the column on the left :-)