Active Directory Server Object Date and Time

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 6 months ago.

  • Author
    Posts
  • #5634

    by alizpak at 2013-03-06 05:34:34

    Hello,

    I have written a script which has one problem and that is its not showing me date created and modified also I need to add some extra features like when the script run it ask the date first with the message like (from which date you want the result from please enter the date).

    I wonder if anyone can help please

    Get-QADComputer -identity "*" | Select Name,OperatingSystem,OperatingSystemVersion,DateCreated,dateModified | Export-Csv Computers.csv

    by alizpak at 2013-03-06 05:57:46

    Ok I have amend my script slightly and I get the result what I wanted but what I need is when I run this script I will ask the date to get the details from rather than bring the whole ad computers.

    Get-QADComputer -identity "*" | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by ArtB0514 at 2013-03-06 06:30:01

    Add a Where-Object clause after the Get-QADComputer to specify the date you're looking for. Here's an example:
    $TargetDate = (Get-Date).AddDays(-30)
    Get-QADComputer | Where-Object {$_.WhenChanged -gt $TargetDate} | Select .....

    by alizpak at 2013-03-06 06:50:32

    Thanks for the reply but this is not what I want..

    What I need is when I run the script it will ask me a question (What Date you want server details from) and it brings the result by looking at the when created date not when changed date.

    Get-QADComputer -identity "*" | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by ArtB0514 at 2013-03-06 07:11:52

    NOT tested, so you might need to do some debugging....
    $TargetDate = Get-Date (Read-Host 'Enter the search date in dd/mm/yyyy form: ')
    Get-QADComputer | Where-Object {($_.WhenCreated).Date -eq $TargetDate} | Select .....

    by alizpak at 2013-03-06 07:42:44

    Hello,

    Thanks for your help I made slight change instead of putting "-eq" I put "-gt" and it worked.

    I need to do more thing on it how I can put a date on it for example from this date till this date, also only brings the data which stats WINDOWS SERVER.??? Please help

    $TargetDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy from: ')

    Set-QADPssnapinsettings -Defaultsizelimit 0

    Get-QADComputer | Where-Object {($_.WhenCreated).Date -gt $TargetDate} | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by ArtB0514 at 2013-03-06 08:35:31

    $TargetDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy form: ')
    Get-QADComputer -SizeLimit 0 -OperatingSystem *Server* | Where-Object {($_.WhenCreated).Date -gt $TargetDate} | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by alizpak at 2013-03-06 08:43:05

    Thanks for this reply.
    How do I do the date range filter for eg from 01/01/2013 to 31/01/2013.

    by ArtB0514 at 2013-03-06 08:53:07

    Change $TargetDate to $StartDate and add a new variable $EndDate (with the day AFTER the one you want to stop at) then update the Where-Object clause:

    Where-Object {($_.WhenCreated).Date -gt $StartDate -and ($_.WhenCreated).Date -lt $EndDate}

    by alizpak at 2013-03-07 01:34:38

    Please see below script this is what I have changed but it seems to pick up every single entry from the AD in theory not working as requirement. please help

    $StartDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy From: ')
    $EndDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy To: ')

    Get-QADComputer -Sizelimit 0 | Where-Object {($_.WhenCreated).Date -gt $starttDate -and ($_.WhenCreated).Date -lt $EndDate} | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by DexterPOSH at 2013-03-07 01:49:54

    Hi ,
    I just want to ask that instead of using the where-object to filter , won't it be good if we use the -createdbefore and -createdafter parameters available with the Get-QADComputer cmdlet.
    Following is an example
    Get-QADComputer -CreatedAfter "04/13/2011" -CreatedBefore "04/15/2011"

    Hope it helps

    by alizpak at 2013-03-07 02:23:27

    Can you please check this script i amended and advise

    $StartDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy From: ')
    $EndDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy To: ')

    Get-QADComputer -Sizelimit 0 | $_.CreatedBefore $startDate -and $_.CreatedAfter $EndDate | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by alizpak at 2013-03-07 02:55:24

    Finally below script works as I wanted..

    $StartDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy From: ')
    $EndDate = Get-Date (Read-Host 'Enter the Search date in dd/mm/yyyy To: ')

    Get-QADComputer -Sizelimit 0 | Where-Object {($_.WhenCreated).Date -gt $startDate -and ($_.WhenCreated).Date -lt $EndDate} | Select Name,OperatingSystem,OperatingSystemVersion,WhenCreated,WhenChanged,CanonicalName | Export-Csv Computers.csv

    by DexterPOSH at 2013-03-08 03:42:03

    [quote="DexterPOSH"]Hi ,
    Following is an example
    Get-QADComputer -CreatedAfter "04/13/2011" -CreatedBefore "04/15/2011"

    Hope it helps[/quote]

    Hi alizpak.

    Does the above quoted way doesn't work for you....??
    It's good that you got it working but you can filter the Computer accounts in the Get-QADComputer itself...

    Does that makes sense ?

    by alizpak at 2013-03-11 06:20:42

    The way I wanted to design the script was when the script runs then user can input the date on the cmdlet rather then go and change the script and run, and i put the extra "T" on $startDate so it was completely skipping the command and generating result. So now it searching through the loop and get me the result what I wanted.

    Thank you soo much help and support. This forum is just too good I get all the help what I need to learn powershell more and more

You must be logged in to reply to this topic.