miércoles, 15 de marzo de 2017

WINDOWS. PS. Objects changed/created control by date

If you need or you want know when one user is created or modified at AD this post is for you:

We need one variable date (xuserdate) to found the created/modify user data info.

[ ] Example 1: 

$xuserdate = [datetime] "2/22/2017"
Get-ADObject -Filter ‘whenchanged -gt $xuserdate’ | Group-Object objectclass



In this example show all AD object.

To check $xuserdate



[ ] Example 2:

Get-ADUser -Identity pedro.Hernandez -Properties *



$xuserdate = [datetime] "2/22/2017"
Get-ADObject -Filter ‘whenchanged -gt $xuserdate’ | Group-Object objectclass


 

$xuserdate = [datetime] "2/22/2017"
Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.DisplayName -like '*'} | Select Name, DistinguishedName

Get-ADObject -Filter ‘whencreated -gt $xuserdate’|  Select Name, DistinguishedName

Get-ADObject -Filter ‘whencreated -gt $xuserdate’|  Select Name, DistinguishedName



[ ] ONE SCRIPT

&&&&&&&&&&&&&&&&&& SCRIPT &&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

cls

Import-Module ActiveDirectory

#=====================

#INITIALIZE VARIABLES
#=====================

$mailbody2 = $nul

$mailbody3 = $nul
$mailbody4 = $nul
$mailbody5 = $nul
$mailbody6 = $nul
$mailbody7 = $nul


$ReportFile = ".\ADReport.txt" 


#CURRENT DAY

#$xuserdate = get-date -format M.d.yyyy 

#YESTERDAY

#$xuserdate =(get-date).AddDays(-1).ToString("M-d-yyyy")

#ONE DATE

$xuserdate = [datetime] "2/15/2017"



#================

#DEFINE VARIABLES
#================


$mailbody2 = @()

$mailbody3 = @()
$mailbody4 = @()
$mailbody5 = @()
$mailbody6 = @()
$mailbody7 = @()
$mailbody8 = @()


#===========

#BODY SCRIPT
#===========

if((test-path $ReportFile) -like $false)

{
new-item $ReportFile -type file
}
else
{
del $ReportFile
}

#======================

# QUERIES *WHENCHANGED*
#======================

$mailbody2 += "`n [0]*** WHENCHANGED FROM: " + $xuserdate + " ***" |  Out-File -Append $ReportFile   -NoClobber

$mailbody2 += Get-ADObject -Filter ‘whenchanged -gt $xuserdate’ | Group-Object objectclass |  Out-File -Append $ReportFile -NoClobber
$mailbody3 +=  "`n===[1. serviceConnectionPoint]=========================================================================================`n" |  Out-File -Append $ReportFile   -NoClobber
$mailbody3 += Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.ObjectClass -like 'serviceConnectionPoint'} | Sort-Object -Property whencreated |  Select Name, DistinguishedName |  Out-File -Append $ReportFile -NoClobber
$mailbody4 +=  "`n===[2. organizationalUnit]=============================================================================================`n" |  Out-File -Append $ReportFile  -NoClobber
$mailbody4 += Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.ObjectClass -like 'organizationalUnit'} | Sort-Object -Property whencreated |  Select Name, DistinguishedName  | Out-File -Append $ReportFile   -NoClobber
$mailbody5 +=  "`n===[3. person]=============================================================================================`n" |  Out-File -Append $ReportFile   -NoClobber
$mailbody5 +=Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.ObjectClass -like 'person'} | Sort-Object -Property whencreated |  Select Name, DistinguishedName, description  | Out-File -Append $ReportFile   -NoClobber
$mailbody6 +=  "`n===[4. computer]=============================================================================================`n" |  Out-File -Append $ReportFile   -NoClobber
$mailbody6 +=Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.ObjectClass -like 'computer'} | Sort-Object -Property whencreated |  Select Name, DistinguishedName  | Out-File -Append $ReportFile   -NoClobber
$mailbody7 +=  "`n===[5. dnsNodeperson]=============================================================================================`n" |  Out-File -Append $ReportFile   -NoClobber
$mailbody7 +=Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.ObjectClass -like 'dnsNode'} | Sort-Object -Property whencreated |  Select Name, DistinguishedName  | Out-File -Append $ReportFile   -NoClobber
$mailbody8 +=  "`n===[6. group]=============================================================================================`n" |  Out-File -Append $ReportFile   -NoClobber
$mailbody8 +=Get-ADObject -Filter ‘whencreated -gt $xuserdate’| where{$_.ObjectClass -like 'group'} | Sort-Object -Property whencreated |  Select Name, description, DistinguishedName  | Out-File -Append $ReportFile   -NoClobber



&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

The result is saved in a  ".\ADReport.txt"  file.

This script have a lot of possibilities with a few changes.




by GoN | Published: March 15, 2017 | Last Updated:

No hay comentarios: