?
Solved

Help with Powershell script finding AD Disabled users and exporting as a HTML

Posted on 2014-08-14
4
Medium Priority
?
1,727 Views
Last Modified: 2014-08-14
I have powershell script that will find disabled accounts in AD from the last 7 days and export them into a CSV file into a file share.  I need to find a way to export\convert them into a nice html format.  

Below is the following script.

Import-Module activedirectory
$filename = "\\ifcfs01\Information Technology\IT Security Logs\AD Disabled Account - Report\Weekly\Disabled_Accounts_Report_" + (Get-Date -Format "MM_dd_yyyy_HH_mm").ToString() + ".csv"

Get-Aduser -Filter * -Properties * | Select-Object Name,SamAccountName,whenChanged,Enabled,AccountExpirationDate,@{Name="LastLogonTimestamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}},@{Name="Lastlgon"; Expression={[DateTime]::FromFileTime($_.lastlogon)}},LastlogonDate | Where-Object {$_.Enabled -eq $false -AND $_.WhenChanged -ge ((Get-Date).AddDays(-7))} | Export-Csv $filename
0
Comment
Question by:tools2teach
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 40261058
You can use ConvertTo-HTML..
Example..
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$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>"

Get-Aduser -Filter * -Properties * | Select-Object Name,SamAccountName,whenChanged,Enabled,AccountExpirationDate,@{Name="LastLogonTimestamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}},@{Name="Lastlgon"; Expression={[DateTime]::FromFileTime($_.lastlogon)}},LastlogonDate | Where-Object {$_.Enabled -eq $false -AND $_.WhenChanged -ge ((Get-Date).AddDays(-7))} |
Select-Object Name,SamAccountName,whenChanged,Enabled,AccountExpirationDate,@{Name="LastLogonTimestamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}},@{Name="Lastlgon"; Expression={[DateTime]::FromFileTime($_.lastlogon)}},LastlogonDate | Where-Object {$_.Enabled -eq $false -AND $_.WhenChanged -ge ((Get-Date).AddDays(-7))} |
ConvertTo-HTML -head $a -body "<H2>AD Disabled users Information</H2>" | 
Out-File C:\temp\Test.htm

Invoke-Expression C:\temp\Test.htm

Open in new window

Refer following article for more details..
http://technet.microsoft.com/en-us/library/ff730936.aspx
0
 
LVL 11

Expert Comment

by:Giladn
ID: 40261059
You can convert CSV to HTML
http://www.convertcsv.com/csv-to-html.htm

you can only export to csv as far as I know via powershell, this is your only option, you can do it dynamicaly
if you have a website running with PHP/JAVASCRIPT , have a look at this post:
http://stackoverflow.com/questions/518795/dynamically-display-a-csv-file-as-an-html-table-on-a-web-page

G
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40261070
@tools2teach, There is a type in my code.. you can remove line 9 (It's a duplication)..
0
 

Author Closing Comment

by:tools2teach
ID: 40261881
Sweet!
0

Featured Post

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question