Link to home
Start Free TrialLog in
Avatar of Sarang Tinguria
Sarang TinguriaFlag for India

asked on

Get powershell output of mentioned script in HTML

I have found a very good script here made by our own EE friend Krzysztof Pytko in below link, this gives me all the information I need however I need the output in html file under tabular format.

Can you guys help me with it.

https://kpytko.files.wordpress.com/2013/12/adreport-ps1-v2.doc
Avatar of footech
footech
Flag of United States of America image

The script is built to output its data in a report format, making it more easily human readable.  It's got a lot (347) of Write-Host commands, and those all only output to the screen (you can't redirect them to a file or anything).  So to try to refactor this to output into HTML tables would be a lot of work - not only changing all the Write-Host commands, but adding a number of others to combine data into arrays, convert to HTML, etc.  I'm not sure how you would even combine all the output in a tabular format, given what the output is like now.  At the very least you would have to provide sample output from the script as is, then reformat it as you want it to appear.

In other words, I think it's too much to ask here.  Perhaps in Gigs.
Avatar of Sarang Tinguria

ASKER

Hey Footech,

Thank you for your time here, I understand it is lot of work can you or anyone help me with a script that would fetch below details in HTML tabular format. I have deleted most of the extra information from the script output however below would I need specifically,

Forest name
Active Directory schema version
Microsoft Exchange version
Forest Functional Level
Domains in this forest
IP address (v4)    :  
IP address (v6)    :  (none)
OS type            :  
SYSVOL replication :  DFS-R
Schema master
Domain Naming master
PDC Emulator master
RID master
Infrastructure master
DNS domain name
NetBIOS domain name
Domain Functional Level
SYSVOL replication method
List of Domain Controllers
List of Read-Only Domain Controllers
Domain objects statistic:
Total number of computer objects :
Server systems
Total number of user objects  :
Total number of Domain Administrators:
Server roles installed on this DC
OS Version of DC
RAM in GB
System Model
My approach would be to write a replacement function for write-host with the parameters used, and creating HTML code instead.
ASKER CERTIFIED SOLUTION
Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Script from Jason was helpful and on the track however was not meeting my purpose completely So I went and found a script with some information (I lost the link of that script) and after multiple changes I created below.


# Import Module Active Directory:
      Write-Host "Importing Active Directory Module" -ForegroundColor 'Green'
       Import-Module -Name ActiveDirectory


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

#### HTML file

# Setting Variables
#
      $date = (Get-Date -Format d_MMMM_yyyy).toString()
      $filePATH = "$env:userprofile\Desktop\"
      $fileNAME = "AD_Info_" + $date + ".html"
      $file = $filePATH + $fileNAME
#
# Active Directory Variables
      $adFOREST = Get-ADForest
      $adDOMAIN = Get-ADDomain

      
      $hostname = $env:computername                
    $adFORESTNAME = $adFOREST.Name
    $Schema = Get-ADObject (Get-ADRootDSE).schemaNamingContext -Property objectVersion |Select -ExpandProperty objectversion
      $adFORESTMODE = $adFOREST.ForestMode
      $adFORESTDOMAIN = $adFOREST | select -ExpandProperty Domains
      $adFORESTROOTDOMAIN = $adFOREST.RootDomain
      $adFORESTSchemaMaster = $adFOREST.SchemaMaster
      $adFORESTNamingMaster = $adFOREST.DomainNamingMaster
      $adFORESTGlobalCatalog = $adFOREST | select -ExpandProperty GlobalCatalogs
      $adFORESTSites = $adFOREST  |  select -ExpandProperty Sites
          

   
      $adDomainName = $adDOMAIN.Name
    $Domaincontrollername= (Get-WmiObject -class Win32_OperatingSystem).Caption
      $adDOMAINNetBiosName = $adDOMAIN.NetBIOSName
      $adDOMAINDomainMode = $adDOMAIN.DomainMode
      $adDOMAINParentDomain = $adDOMAIN.ParentDomain
    $adDomainName = "$env:userdnsdomain"
      $adDOMAINPDCEMu = $adDOMAIN.PDCEmulator
      $adDOMAINRIDMaster = $adDOMAIN.RIDMaster
      $adDOMAINInfra = $adDOMAIN.InfrastructureMaster
      $adDOMAINChildDomain = $adDOMAIN | select -ExpandProperty ChildDomains
      $adDOMAINReplica = $adDOMAIN | select -ExpandProperty ReplicaDirectoryServers
      $adDOMAINReadOnlyReplica = $adDOMAIN | select -ExpandProperty ReadOnlyReplicaDirectoryServers
    $IPaddressv4 = $ip4 |select -ExpandProperty IPAddress
    $GatewayIP = Get-NetIPConfiguration | Foreach IPv4DefaultGateway |select -ExpandProperty Nexthop
    $DNSServer = Get-NetIPConfiguration | select DNSSERVER -ExpandProperty DNSSERVER |Select ServerAddresses -ExpandProperty Serveraddresses
    $Manufacturer = get-wmiobject win32_computersystem | select Manufacturer -ExpandProperty Manufacturer
    $AllDC = Get-ADDomainController -Filter * | Select-Object -ExpandProperty name
    $AllUsers = (get-aduser -filter *).count
    $AllComputers = (Get-ADComputer -filter *).count
   
# File Creation

      if (Test-Path "$env:userprofile\Desktop\$filename" ) {
            "`n"
            Write-Warning "file already exists, i am deleting it."
            Remove-Item "$env:userprofile\Desktop\$filename" -Verbose -Force
            "`n"
            Write-Host "Creating a New file Named as $fileNAME" -ForegroundColor 'Green'
            New-Item -Path $filePATH -Name $fileNAME -Type file | Out-Null
            }
      else {
            "`n"
            Write-Host "Creating a New file Named as $fileNAME" -ForegroundColor 'Green'
            New-Item -Path $filePATH -Name $fileNAME -Type file | Out-Null
            "`n"
            }
###HTML Conversion

#
      ConvertTo-Html  -Head $a  -Title "Active Directory Information" -Body "<h1> Detailed information for :  $adFORESTNAME </h1>" > $file

      ConvertTo-Html  -Head $a -Body "<h2> Active Directory Forest Information. </h2>"  >> $file
   
      ConvertTo-Html -Body "<table>
                     
                      <tr><td> Forest Name: </td><td><b> $adFORESTNAME </b></td></tr> `
                                <tr><td> Forest Functional Level: </td><td><b> $adFORESTMODE </b></td></tr> `
                      <tr><td> Domain Functional Level: </td><td><b> $adDOMAINDomainMode </b></td></tr> `
                      <tr><td> Forest Schema Version: </td><td><b> $schema </b></td></tr> `
                                <tr><td> Root Domain : </td><td><b> $adFORESTROOTDOMAIN </b></td></tr> `      
                      <tr><td> Domain Names under this forest: </td><td><b> $adFORESTDOMAIN </b></td></tr> `
                                <tr><td> Current Domain Name: </td><td><b> $adDomainName </b></td></tr> `
                      <tr><td> Current Domain NetBios Name: </td><td><b> $adDOMAINNetBiosName </b></td></tr> `
                      <tr><td> Parent Domain : </td><td><b> $adDOMAINParentDomain </b></td></tr> `
                      <tr><td> Child Domains : </td><td><b> $adDOMAINChildDomain </b></td></tr> `
                      <tr><td> Operating System of this DC: </td><td><b> $Domaincontrollername </b></td></tr> `
                      <tr><td> Domain Naming Master: </td><td><b> $adFORESTNamingMaster </b></td></tr> `      
                                <tr><td> Schema Master: </td><td><b> $adFORESTSchemaMaster </b></td></tr> `      
                                 <tr><td> Domain PDC Emulator : </td><td><b> $adDOMAINPDCEMu </b></td></tr> `      
                                <tr><td> Domain RID Master: </td><td><b> $adDOMAINRIDMaster </b></td></tr> `      
                                 <tr><td> Domain InfraStructure Master : </td><td><b> $adDOMAINInfra </b></td></tr> `
                      <tr><td> Global Catalog Servers : </td><td><b> $adFORESTGlobalCatalog </b></td></tr> `
                      <tr><td> DC in domain : </td><td><b> $AllDC</b></td></tr> `
                      <tr><td> Number of Users : </td><td><b> $AllUsers</b></td></tr> `
                      <tr><td> Number of Computers : </td><td><b> $AllComputers</b></td></tr> `
                                <tr><td> Forest Domain Sites : </td><td><b> $adFORESTSites </b></td></tr></table>" >> $file

      ConvertTo-Html  -Head $a -Body "<h2> Active Directory Domain Controller Information (This DC). </h2>"  >> $file                                     
            
      ConvertTo-Html -Body "<table><tr><td> Computer Name: </td><td><b> $hostname </b></td></tr> `
                      <tr><td> Domain Name: </td><td><b> $adDomainName </b></td></tr> `
                                <tr><td> Manufacturer : </td><td><b> $Manufacturer</b></td></tr> `
                              <tr><td> Replicated Servers : </td><td><b> $adDOMAINReplica</b></td></tr> `
                      <tr><td> IP address : </td><td><b> $IPaddressv4</b></td></tr> `
                      <tr><td> Gateway IP : </td><td><b> $GatewayIP</b></td></tr> `
                      <tr><td> DNS Server : </td><td><b> $DNSServer</b></td></tr> `
                      <tr><td> Read Only Replicated Server : </td><td><b> $adDOMAINReadOnlyReplica </b></td></tr></table>" >> $file

      $Report = "The Report is generated On  $(get-date) by $((Get-Item env:\username).Value) on computer $((Get-Item env:\Computername).Value)"
      $Report  >> $file

      
      Invoke-Expression $file

#### End ###