Powershell commands RRS feed

  • Question

  • Hi guys,

    I need your help to create list of inactive accounts in AD for 30 days. Inactive or created accounts within 2 weeks are not included in the report. Report should be exported to HTML and it has a counter to count all the records and place it at the bottom of the report. Lastlogon should be displayed and other pertinent information for the accounts.

    I'm starting with this command but I'm getting inaccurate result.

    $a = "<style>"
    $a = $a + "BODY{background-color:darkseagreen;}"
    $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
    $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
    $a = $a + "</style>"

    Search-adaccount -usersonly -accountinactive -timespan 90.00:00:00 | where {$_.enabled} |select name, samaccountname,userprincipalname, enabled, lastlogondate,lockedout,passwordexpired,passwordneverexpires |ConvertTo-HTML -head $a | Out-File C:\Scripts\Test.htm

    Invoke-Expression C:\Scripts\Test.htm

    Thank you in advance for the help!

    Thursday, July 30, 2015 5:31 AM


All replies

  • Check this link.


    (Please click on "Vote as Helpful" and/or "Mark as Answer", if it has helped you. )

    • Marked as answer by Frank Shen5 Tuesday, August 11, 2015 3:01 AM
    Thursday, July 30, 2015 5:35 AM
  • Hi,

    " I'm getting inaccurate result", what is expected and what are you getting.

    If you leave the html part now, is the Search-ADAccount resulting the correct data.



    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Thursday, July 30, 2015 6:36 AM