Update Information Script

#########################################################################################
#                                                                                        #
#    NAME: Update Information Script                                                        #
#    VERSION: 1                                                                            #
#    CODE BY: Jesse Hamrick – http://www.powershellpro.com                                #
#    AUTHOR: Arjen Huitema                                                                #
#    DATE: 05-12-2011                                                                    #
#    COMMENT: To run the code below make sure your computer has Excel and MBSA installed    #
#                                                                                        #
#########################################################################################

# Variables.
$strComputer = Read-Host “Enter Computer Name”
$strDomain = Read-Host “Enter the Domain Name”

# Default Install Path for MBSA 2.1. If your install path is different, change line below.
$Path = “C:Archivos de programaMicrosoft Baseline Security Analyzer 2"

# Create new com object Excel
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

# Assign each worksheet to a variable and name the worksheet.
$Sheet1 = $Excel.Worksheets.Item(1)
$Sheet1.Name = “Patches”

#Create Heading for Anti-Virus Sheet
$Sheet1.Cells.Item(1,1) = “Computer Name”
$Sheet1.Cells.Item(1,2) = “Patch Information”

$intRow = 2
$WorkBook = $sheet1.UsedRange
$WorkBook.Interior.ColorIndex = 20
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

Set-Location $Path
$cmd = “cmd /c mbsacli.exe /Target $strDomain$strComputer /n OS+SQL+IIS+Password >C:MBSA$strComputer.txt”
Invoke-Expression $cmd

$logResults = (Get-Content “C:MBSA$strComputer.txt”) -match “Missing”
foreach($Item in $logResults){
$Sheet1.Cells.Item($intRow, 1) = $strComputer
$Sheet1.Cells.Item($intRow, 2) = $Item
$intRow = $intRow + 1
}

#Auto Fit all sheets in the Workbook
$WorkBook = $colorItem.UsedRange
$WorkBook.EntireColumn.AutoFit()
clear

#delete Temp File
Remove-Item “C:MBSA$strComputer.txt”

Partition Alignment Report

#########################################################################################
#                                                                                        #
#    NAME: Partition Alignment Report                                                    #
#    VERSION: 1                                                                            #
#    AUTHOR: Jonathan Kehayias (The Rambling DBA)                                        #
#    BASED ON: Workstation/Server Audit script by Alan Renouf (Virtual-AL)                #
#                                                                                        #
#    USAGE: PartitionAlignmentReport.ps1 ‘C:pathtolistofservers’                        #
#                                                                                        #
#    COMMENT: The file is optional and needs to be a plain text list of computers to be    #
#    audited one on each line.                                                            #
#                                                                                        #
#    05-12-2011: Minor changes by Arjen Huitema                                              #
#                                                                                        #
#########################################################################################

param( [string] $auditlist)

if ($auditlist -eq ""){
    Write-Host "No list specified, using $env:computername"
    $targets = Get-Content C:Test.txt
}
else
{
    if ((Test-Path $auditlist) -eq $false)
    {
        Write-Host "Invalid audit path specified: $auditlist"
        exit
    }
    else
    {
        Write-Host "Using Audit list: $auditlist"
        $Targets = Get-Content C:Test.txt
    }
}

$Date = Get-Date

$Filename = ".Partition_Alignment_Report_" + $date.Hour + $date.Minute + "_" + $Date.Day + "-" + $Date.Month + "-" + $Date.Year + ".htm"

Write-Host ""
Write-Host "Building Report"

#region Report Header
    $Report = @"
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html ES_auditInitialized=’false’><head><title>Audit</title>
    <META http-equiv=Content-Type content=’text/html; charset=windows-1252′>
    <STYLE type=text/css>   
        DIV .expando {DISPLAY: block; FONT-WEIGHT: normal; FONT-SIZE: 8pt; RIGHT: 10px; COLOR: #ffffff; FONT-FAMILY: Tahoma; POSITION: absolute; TEXT-DECORATION: underline}
        TABLE {TABLE-LAYOUT: fixed; FONT-SIZE: 100%; WIDTH: 100%}
        #objshowhide {PADDING-RIGHT: 10px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; Z-INDEX: 2; CURSOR: hand; COLOR: #000000; MARGIN-RIGHT: 0px; FONT-FAMILY: Tahoma; TEXT-ALIGN: right; TEXT-DECORATION: underline; WORD-WRAP: normal}
        .heading0_expanded {BORDER-RIGHT: #bbbbbb 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #bbbbbb 1px solid; DISPLAY: block; PADDING-LEFT: 8px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 0px; BORDER-LEFT: #bbbbbb 1px solid; WIDTH: 100%; CURSOR: hand; COLOR: #FFFFFF; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #bbbbbb 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 2.25em; BACKGROUND-COLOR: #CCCC00}
        .heading_collapsed {BORDER-RIGHT: #bbbbbb 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #bbbbbb 1px solid; DISPLAY: block; PADDING-LEFT: 16px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 5px; BORDER-LEFT: #bbbbbb 1px solid; WIDTH: 100%; CURSOR: hand; COLOR: #ffffff; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #bbbbbb 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 2.25em; BACKGROUND-COLOR: #7BA7C7}
        .heading_expanded {BORDER-RIGHT: #bbbbbb 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #bbbbbb 1px solid; DISPLAY: block; PADDING-LEFT: 16px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 5px; BORDER-LEFT: #bbbbbb 1px solid; WIDTH: 100%; CURSOR: hand; COLOR: #ffffff; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #bbbbbb 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 2.25em; BACKGROUND-COLOR: #A5A5A5}
        .tableDetail {BORDER-RIGHT: #bbbbbb 1px solid; BORDER-TOP: #bbbbbb 1px solid; DISPLAY: block; PADDING-LEFT: 16px; FONT-SIZE: 8pt;MARGIN-BOTTOM: -1px; PADDING-BOTTOM: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #bbbbbb 1px solid; WIDTH: 100%; COLOR: #000000; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #bbbbbb 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; BACKGROUND-COLOR: #f9f9f9}
        .filler {BORDER-RIGHT: medium none; BORDER-TOP: medium none; DISPLAY: block; BACKGROUND: none transparent scroll repeat 0% 0%; MARGIN-BOTTOM: -1px; FONT: 100%/8px Tahoma; MARGIN-LEFT: 43px; BORDER-LEFT: medium none; COLOR: #ffffff; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: medium none; POSITION: relative}
        .Solidfiller {BORDER-RIGHT: medium none; BORDER-TOP: medium none; DISPLAY: block; BACKGROUND: none transparent scroll repeat 0% 0%; MARGIN-BOTTOM: -1px; FONT: 100%/8px Tahoma; MARGIN-LEFT: 0px; BORDER-LEFT: medium none; COLOR: #000000; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: medium none; POSITION: relative; BACKGROUND-COLOR: #000000}
        td {VERTICAL-ALIGN: TOP; FONT-FAMILY: Tahoma}
        th {VERTICAL-ALIGN: TOP; COLOR: #000000; TEXT-ALIGN: left}
    </STYLE>
    <SCRIPT language=vbscript>
        strShowHide = 1
        strShow = "show"
        strHide = "hide"
        strShowAll = "show all"
        strHideAll = "hide all"
   
    Function window_onload()
        If UCase(document.documentElement.getAttribute("ES_auditInitialized")) <> "TRUE" Then
            Set objBody = document.body.all
            For Each obji in objBody
                If IsSectionHeader(obji) Then
                    If IsSectionExpandedByDefault(obji) Then
                        ShowSection obji
                    Else
                        HideSection obji
                    End If
                End If
            Next
            objshowhide.innerText = strShowAll
            document.documentElement.setAttribute "ES_auditInitialized", "true"
        End If
    End Function
   
    Function IsSectionExpandedByDefault(objHeader)
        IsSectionExpandedByDefault = (Right(objHeader.className, Len("_expanded")) = "_expanded")
    End Function
   
    Function document_onclick()
        Set strsrc = window.event.srcElement
        While (strsrc.className = "sectionTitle" or strsrc.className = "expando")
            Set strsrc = strsrc.parentElement
        Wend
        If Not IsSectionHeader(strsrc) Then Exit Function
        ToggleSection strsrc
        window.event.returnValue = False
    End Function
   
    Sub ToggleSection(objHeader)
        SetSectionState objHeader, "toggle"
    End Sub
   
    Sub SetSectionState(objHeader, strState)
        i = objHeader.sourceIndex
        Set all = objHeader.parentElement.document.all
        While (all(i).className <> "container")
            i = i + 1
        Wend
        Set objContainer = all(i)
        If strState = "toggle" Then
            If objContainer.style.display = "none" Then
                SetSectionState objHeader, "show"
            Else
                SetSectionState objHeader, "hide"
            End If
        Else
            Set objExpando = objHeader.children.item(1)
            If strState = "show" Then
                objContainer.style.display = "block"
                objExpando.innerText = strHide
   
            ElseIf strState = "hide" Then
                objContainer.style.display = "none"
                objExpando.innerText = strShow
            End If
        End If
    End Sub
   
    Function objshowhide_onClick()
        Set objBody = document.body.all
        Select Case strShowHide
            Case 0
                strShowHide = 1
                objshowhide.innerText = strShowAll
                For Each obji In objBody
                    If IsSectionHeader(obji) Then
                        HideSection obji
                    End If
                Next
            Case 1
                strShowHide = 0
                objshowhide.innerText = strHideAll
                For Each obji In objBody
                    If IsSectionHeader(obji) Then
                        ShowSection obji
                    End If
                Next
        End Select
    End Function
   
    Function IsSectionHeader(obj) : IsSectionHeader = (obj.className = "heading_collapsed") Or (obj.className = "heading_expanded"): End Function
    Sub HideSection(objHeader) : SetSectionState objHeader, "hide" : End Sub
    Sub ShowSection(objHeader) : SetSectionState objHeader, "show": End Sub
    </SCRIPT>
    </HEAD>
    <BODY>
    <p><b>    <font face="Arial" size="5"><b><i>Server Partition Alignment Report<hr size="4" color="#CCCC00"></i></b></font>
    <font face="Arial" size="1"><b><i><a href="http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/03/01/getting-partition-offset-information-with-powershell.aspx">Version 1.0 by Jonathan Kehayias</a></i></b></font><br>
    <font face="Arial" size="1">Report generated on $Date </font></p>
    <TABLE cellSpacing=0 cellPadding=0>
        <TBODY>
            <TR>
                <TD>
                    <DIV id=objshowhide tabIndex=0><FONT face=Arial></FONT></DIV>
                </TD>
            </TR>
        </TBODY>
    </TABLE>
"@
#endregion

$header = "
        <DIV class=container>
            <DIV class={0}>
                <SPAN class=sectionTitle tabIndex=0>{1}</SPAN>
                <A class=expando href=’#’></A>
            </DIV>
            <DIV class=container>
                <DIV class=tableDetail>"
$footer = "
                </DIV>
            </DIV>
        </DIV>
        <DIV class=filler></DIV>"

Foreach ($Target in $Targets)
{
$Report+= $header -f "heading_collapsed", $Target

#region Disk Configuration

$drives = Get-WmiObject Win32_DiskDrive -ComputerName $Target

$s = New-Object System.Management.ManagementObjectSearcher
$s.Scope = "\$Targetrootcimv2"
$s2 = New-Object System.Management.ManagementObjectSearcher
$s2.Scope = "\$Targetrootcimv2"

$qPartition = new-object System.Management.RelatedObjectQuery
$qPartition.RelationshipClass = ‘Win32_DiskDriveToDiskPartition’

$qLogicalDisk = new-object System.Management.RelatedObjectQuery
$qLogicalDisk.RelationshipClass = ‘Win32_LogicalDiskToPartition’

$Report+= $header -f "heading_expanded", "Partitions"

$Report += "
                <TABLE>
                    <tr>
                        <th width=’15%’><b>Name</b></th>
                        <th width=’10%’><b>Drive Letter</b></th>
                        <th width=’10%’><b>Label</b></th>
                        <th width=’5%’><b>Size(GB)</b></th>
                        <th width=’10%’><b>File System</b></th>
                        <th width=’10%’><b>BlockSize</b></th>
                        <th width=’10%’><b>Offset</b></th>
                        <th width=’5%’><b>Index</b></th>
                        <th width=’5%’><b>IsPrimary</b></th>
                        <th width=’10%’><b>Disk Free Space</b></th>
                        <th width=’10%’><b>% Free Space</b></th>
                    </tr>"
   
$drives | Sort-Object DeviceID | % {
   $qPartition.SourceObject = $_
   $s.Query= $qPartition
   $s.Get()| where {$_.Type -ne ‘Unknown’} |% {
  
   $partition = $_;
  
   $partitionSize = ([math]::round(($($_.Size)/1GB),1))
       $qLogicalDisk.SourceObject = $_
       $s2.Query= $qLogicalDisk.QueryString
       $s2.Get()|% {
      
           $disksize = [math]::round(($_.size / 1048576))
        $freespace = [math]::round(($_.FreeSpace / 1048576))
        $percFreespace=[math]::round(((($_.FreeSpace / 1048576)/($objDisk.Size / 1048676)) * 100),0)

       $Report += "
                    <tr>
                        <td width=’15%’>$($partition.Name)</td>
                        <td width=’10%’>$($_.DeviceID)</td>
                        <td width=’10%’>$($_.VolumeName)</td>
                        <td width=’5%’>$PartitionSize GB</td>
                        <td width=’10%’>$($_.FileSystem)</td>
                        <td width=’10%’>$($partition.BlockSize)</td>
                        <td width=’10%’>$($partition.StartingOffset)</td>
                        <td width=’5%’>$($partition.DiskIndex)</td>
                        <td width=’5%’>$($partition.PrimaryPartition)</td>
                        <td width=’10%’>$Freespace MB</td>
                        <td width=’10%’>$percFreespace%</td>
                    </tr>
"      
        }
    }
}
$Report+= "
                </TABLE>
"
$Report+= $footer
$Report+= $footer
$Report+= $footer

#endregion  Disk Configuration
}

$Report+= @"
    </body>
    </html>
"@
$Report | out-file -encoding ASCII -filepath $Filename

Inventories running services

#########################################################################################
#                                                                                        #
#    NAME: ListServices                                                                    #
#    VERSION: 1                                                                            #
#    AUTHOR: Arjen Huitema                                                                #
#    DATE: 05-12-2011                                                                    #
#    COMMENT: Script Inventories running services.                                        #
#                                                                                        #
#########################################################################################

# —————————————————————————————
# List services and status
# —————————————————————————————
 
if (-not ([appdomain]::CurrentDomain.getassemblies() |? {$_.ManifestModule -like "system.serviceprocess"})) {[void][System.Reflection.Assembly]::LoadWithPartialName(‘system.serviceprocess’)}
 
$servers=Get-Content C:Test.txt
 
function ListServices
{
 
$all = $null
 
foreach($s in $servers)
{
  if ($all -eq $null) { $all = [System.ServiceProcess.ServiceController]::GetServices($s) }
  else
  {
    $all = $all + [System.ServiceProcess.ServiceController]::GetServices($s)
  }
}
 
return $all
 
}
 
ListServices | Format-Table -AutoSize -Property MachineName,DisplayName,Status

Computer Inventory

#########################################################################################
#                                                                                        #
#    NAME: Computer Inventory                                                            #
#    VERSION: 2                                                                            #
#    AUTHOR: Jesse Hamrick                                                                #
#    DATE: 25-02-2009                                                                    #
#    WEB: www.PowerShellPro.com                                                            #
#    COMMENT: Script Inventories Computers and sends results to an excel file.            #
#                                                                                        #
#    05-12-2011: Minor changes by Arjen Huitema                                              #
#                                                                                        #
#########################################################################################

# Functions Section
# —————————————————————————————
# Function Name ‘WMILookup’ – Gathers info using WMI and places results in Excel
# —————————————————————————————
Function WMILookup {
foreach ($StrComputer in $colComputers){
        $GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer
        $GenItems2 = gwmi Win32_OperatingSystem -Comp $StrComputer
        $SysItems1 = gwmi Win32_BIOS -Comp $StrComputer
        $SysItems2 = gwmi Win32_TimeZone -Comp $StrComputer
        $SysItems3 = gwmi Win32_WmiSetting -Comp $StrComputer
        $ProcItems1 = gwmi Win32_Processor -Comp $StrComputer
        $MemItems1 = gwmi Win32_PhysicalMemory -Comp $StrComputer
        $memItems2 = gwmi Win32_PhysicalMemoryArray -Comp $StrComputer
        $DiskItems = gwmi Win32_LogicalDisk -Comp $StrComputer
        $NetItems = gwmi Win32_NetworkAdapterConfiguration -Comp $StrComputer |`
                    where{$_.IPEnabled -eq "True"}
       
               
# Populate General Sheet(1) with information
    foreach ($objItem in $GenItems1){
        $Sheet1.Cells.Item($intRow, 1) = $StrComputer
        Switch($objItem.DomainRole)
            {
            0{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Workstation"}
            1{$Sheet1.Cells.Item($intRow, 2) = "Member Workstation"}
            2{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Server"}
            3{$Sheet1.Cells.Item($intRow, 2) = "Member Server"}
            4{$Sheet1.Cells.Item($intRow, 2) = "Back-up Domain Controller"}
            5{$Sheet1.Cells.Item($intRow, 2) = "Primary Domain Controller"}
            default{"Undetermined"}
            }
        $Sheet1.Cells.Item($intRow, 3) = $objItem.Manufacturer
        $Sheet1.Cells.Item($intRow, 4) = $objItem.Model
        $Sheet1.Cells.Item($intRow, 5) = $objItem.SystemType
        $Sheet1.Cells.Item($intRow, 6) = $objItem.NumberOfProcessors
        $Sheet1.Cells.Item($intRow, 7) = $objItem.TotalPhysicalMemory / 1024 / 1024
        }
    foreach ($objItem in $GenItems2){
        $Sheet1.Cells.Item($intRow, 8) = $objItem.Caption
        $Sheet1.Cells.Item($intRow, 9) = $objItem.csdversion
        }
           
#Populate Systems Sheet
    foreach ($objItem in $SysItems1){
        $Sheet2.Cells.Item($intRow, 1) = $StrComputer
        $Sheet2.Cells.Item($intRow, 2) = $objItem.Name
        $Sheet2.Cells.Item($intRow, 3) = $objItem.SMBIOSbiosVersion
        $Sheet2.Cells.Item($intRow, 4) = $objItem.SerialNumber
        }
    foreach ($objItem in $SysItems2){   
        $Sheet2.Cells.Item($intRow, 5) = $objItem.Caption
        }
    foreach ($objItem in $SysItems3){
        $Sheet2.Cells.Item($intRow, 6) = $objItem.BuildVersion
        }
               
#Populate Processor Sheet       
    foreach ($objItem in $ProcItems1){
        $Sheet3.Cells.Item($intRowCPU, 1) = $StrComputer
        $Sheet3.Cells.Item($intRowCPU, 2) = $objItem.DeviceID+" "+$objItem.Name
        $Sheet3.Cells.Item($intRowCPU, 3) = $objItem.Description
        $Sheet3.Cells.Item($intRowCPU, 4) = $objItem.family
        $Sheet3.Cells.Item($intRowCPU, 5) = $objItem.currentClockSpeed
        $Sheet3.Cells.Item($intRowCPU, 6) = $objItem.l2cacheSize
        $Sheet3.Cells.Item($intRowCPU, 7) = $objItem.UpgradeMethod
        $Sheet3.Cells.Item($intRowCPU, 8) = $objItem.SocketDesignation
        $intRowCPU = $intRowCPU + 1
        }
               
#Populate Memory Sheet
$bankcounter = 1
    foreach ($objItem in $memItems2){
        $MemSlots = $objItem.MemoryDevices +1
           
    foreach ($objItem in $MemItems1){
        $Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
        $Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
    if($objItem.BankLabel -eq ""){
        $Sheet4.Cells.Item($intRowMem, 3) = $objItem.DeviceLocator}
    Else{$Sheet4.Cells.Item($intRowMem, 3) = $objItem.BankLabel}
        $Sheet4.Cells.Item($intRowMem, 4) = $objItem.Capacity/1024/1024
        $Sheet4.Cells.Item($intRowMem, 5) = $objItem.FormFactor
        $Sheet4.Cells.Item($intRowMem, 6) = $objItem.TypeDetail
        $intRowMem = $intRowMem + 1
        $bankcounter = $bankcounter + 1
        }
    while($bankcounter -lt $MemSlots)   
        {
        $Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
        $Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
        $Sheet4.Cells.Item($intRowMem, 3) = "is Empty"
        $Sheet4.Cells.Item($intRowMem, 4) = ""
        $Sheet4.Cells.Item($intRowMem, 5) = ""
        $Sheet4.Cells.Item($intRowMem, 6) = ""
        $intRowMem = $intRowMem + 1
        $bankcounter = $bankcounter + 1
        }
    }
           
           
#Populate Disk Sheet
    foreach ($objItem in $DiskItems){
        $Sheet5.Cells.Item($intRowDisk, 1) = $StrComputer
        Switch($objItem.DriveType)
        {
        2{$Sheet5.Cells.Item($intRowDisk, 2) = "Floppy"}
        3{$Sheet5.Cells.Item($intRowDisk, 2) = "Fixed Disk"}
        5{$Sheet5.Cells.Item($intRowDisk, 2) = "Removable Media"}
        default{"Undetermined"}
        }
        $Sheet5.Cells.Item($intRowDisk, 3) = $objItem.DeviceID
        $Sheet5.Cells.Item($intRowDisk, 4) = $objItem.Size/1024/1024
        $Sheet5.Cells.Item($intRowDisk, 5) = $objItem.FreeSpace/1024/1024
        $intRowDisk = $intRowDisk + 1
        }
       
#Populate Network Sheet
    foreach ($objItem in $NetItems){
        $Sheet6.Cells.Item($intRowNet, 1) = $StrComputer
        $Sheet6.Cells.Item($intRowNet, 2) = $objItem.Caption+" (enabled)"
        $Sheet6.Cells.Item($intRowNet, 3) = $objItem.DHCPEnabled
        $Sheet6.Cells.Item($intRowNet, 4) = $objItem.IPAddress
        $Sheet6.Cells.Item($intRowNet, 5) = $objItem.IPSubnet
        $Sheet6.Cells.Item($intRowNet, 6) = $objItem.DefaultIPGateway
        $Sheet6.Cells.Item($intRowNet, 7) = $objItem.DNSServerSearchOrder
        $Sheet6.Cells.Item($intRowNet, 8) = $objItem.FullDNSRegistrationEnabled
        $Sheet6.Cells.Item($intRowNet, 9) = $objItem.WINSPrimaryServer
        $Sheet6.Cells.Item($intRowNet, 10) = $objItem.WINSSecondaryServer
        $Sheet6.Cells.Item($intRowNet, 11) = $objItem.WINSEnableLMHostsLookup
        $intRowNet = $intRowNet + 1
        }
       
$intRow = $intRow + 1
$intRowCPU = $intRowCPU + 1
$intRowMem = $intRowMem + 1
$intRowDisk = $intRowDisk + 1
$intRowNet = $intRowNet + 1
}
}

# —————————————————————————————
# Function Name ‘WMILookupCred’-Uses Alternative Credential-Gathers info using WMI.
# —————————————————————————————
Function WMILookupCred {
foreach ($StrComputer in $colComputers){
        $GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer -Credential $cred
        $GenItems2 = gwmi Win32_OperatingSystem -Comp $StrComputer -Credential $cred
        $SysItems1 = gwmi Win32_BIOS -Comp $StrComputer -Credential $cred
        $SysItems2 = gwmi Win32_TimeZone -Comp $StrComputer -Credential $cred
        $SysItems3 = gwmi Win32_WmiSetting -Comp $StrComputer -Credential $cred
        $ProcItems1 = gwmi Win32_Processor -Comp $StrComputer -Credential $cred
        $MemItems1 = gwmi Win32_PhysicalMemory -Comp $StrComputer -Credential $cred
        $memItems2 = gwmi Win32_PhysicalMemoryArray -Comp $StrComputer -Credential $cred
        $DiskItems = gwmi Win32_LogicalDisk -Comp $StrComputer -Credential $cred
        $NetItems = gwmi Win32_NetworkAdapterConfiguration -Comp $StrComputer -Credential $cred |`
                    where{$_.IPEnabled -eq "True"}
       
               
# Populate General Sheet(1) with information
    foreach ($objItem in $GenItems1){
        $Sheet1.Cells.Item($intRow, 1) = $StrComputer
        Switch($objItem.DomainRole)
            {
            0{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Workstation"}
            1{$Sheet1.Cells.Item($intRow, 2) = "Member Workstation"}
            2{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Server"}
            3{$Sheet1.Cells.Item($intRow, 2) = "Member Server"}
            4{$Sheet1.Cells.Item($intRow, 2) = "Back-up Domain Controller"}
            5{$Sheet1.Cells.Item($intRow, 2) = "Primary Domain Controller"}
            default{"Undetermined"}
            }
        $Sheet1.Cells.Item($intRow, 3) = $objItem.Manufacturer
        $Sheet1.Cells.Item($intRow, 4) = $objItem.Model
        $Sheet1.Cells.Item($intRow, 5) = $objItem.SystemType
        $Sheet1.Cells.Item($intRow, 6) = $objItem.NumberOfProcessors
        $Sheet1.Cells.Item($intRow, 7) = $objItem.TotalPhysicalMemory / 1024 / 1024
        }
    foreach ($objItem in $GenItems2){
        $Sheet1.Cells.Item($intRow, 8) = $objItem.Caption
        $Sheet1.Cells.Item($intRow, 9) = $objItem.csdversion
        }
           
#Populate Systems Sheet
    foreach ($objItem in $SysItems1){
        $Sheet2.Cells.Item($intRow, 1) = $StrComputer
        $Sheet2.Cells.Item($intRow, 2) = $objItem.Name
        $Sheet2.Cells.Item($intRow, 3) = $objItem.SMBIOSbiosVersion
        $Sheet2.Cells.Item($intRow, 4) = $objItem.SerialNumber
        }
    foreach ($objItem in $SysItems2){   
        $Sheet2.Cells.Item($intRow, 5) = $objItem.Caption
        }
    foreach ($objItem in $SysItems3){
        $Sheet2.Cells.Item($intRow, 6) = $objItem.BuildVersion
        }
               
#Populate Processor Sheet       
    foreach ($objItem in $ProcItems1){
        $Sheet3.Cells.Item($intRowCPU, 1) = $StrComputer
        $Sheet3.Cells.Item($intRowCPU, 2) = $objItem.DeviceID+" "+$objItem.Name
        $Sheet3.Cells.Item($intRowCPU, 3) = $objItem.Description
        $Sheet3.Cells.Item($intRowCPU, 4) = $objItem.family
        $Sheet3.Cells.Item($intRowCPU, 5) = $objItem.currentClockSpeed
        $Sheet3.Cells.Item($intRowCPU, 6) = $objItem.l2cacheSize
        $Sheet3.Cells.Item($intRowCPU, 7) = $objItem.UpgradeMethod
        $Sheet3.Cells.Item($intRowCPU, 8) = $objItem.SocketDesignation
        $intRowCPU = $intRowCPU + 1
        }
               
#Populate Memory Sheet
$bankcounter = 1
    foreach ($objItem in $memItems2){
        $MemSlots = $objItem.MemoryDevices +1
           
    foreach ($objItem in $MemItems1){
        $Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
        $Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
    if($objItem.BankLabel -eq ""){
        $Sheet4.Cells.Item($intRowMem, 3) = $objItem.DeviceLocator}
    Else{$Sheet4.Cells.Item($intRowMem, 3) = $objItem.BankLabel}
        $Sheet4.Cells.Item($intRowMem, 4) = $objItem.Capacity/1024/1024
        $Sheet4.Cells.Item($intRowMem, 5) = $objItem.FormFactor
        $Sheet4.Cells.Item($intRowMem, 6) = $objItem.TypeDetail
        $intRowMem = $intRowMem + 1
        $bankcounter = $bankcounter + 1
        }
    while($bankcounter -lt $MemSlots)   
        {
        $Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
        $Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
        $Sheet4.Cells.Item($intRowMem, 3) = "is Empty"
        $Sheet4.Cells.Item($intRowMem, 4) = ""
        $Sheet4.Cells.Item($intRowMem, 5) = ""
        $Sheet4.Cells.Item($intRowMem, 6) = ""
        $intRowMem = $intRowMem + 1
        $bankcounter = $bankcounter + 1
        }
    }
           
           
#Populate Disk Sheet
    foreach ($objItem in $DiskItems){
        $Sheet5.Cells.Item($intRowDisk, 1) = $StrComputer
        Switch($objItem.DriveType)
        {
        2{$Sheet5.Cells.Item($intRowDisk, 2) = "Floppy"}
        3{$Sheet5.Cells.Item($intRowDisk, 2) = "Fixed Disk"}
        5{$Sheet5.Cells.Item($intRowDisk, 2) = "Removable Media"}
        default{"Undetermined"}
        }
        $Sheet5.Cells.Item($intRowDisk, 3) = $objItem.DeviceID
        $Sheet5.Cells.Item($intRowDisk, 4) = $objItem.Size/1024/1024
        $Sheet5.Cells.Item($intRowDisk, 5) = $objItem.FreeSpace/1024/1024
        $intRowDisk = $intRowDisk + 1
        }
       
#Populate Network Sheet
    foreach ($objItem in $NetItems){
        $Sheet6.Cells.Item($intRowNet, 1) = $StrComputer
        $Sheet6.Cells.Item($intRowNet, 2) = $objItem.Caption+" (enabled)"
        $Sheet6.Cells.Item($intRowNet, 3) = $objItem.DHCPEnabled
        $Sheet6.Cells.Item($intRowNet, 4) = $objItem.IPAddress
        $Sheet6.Cells.Item($intRowNet, 5) = $objItem.IPSubnet
        $Sheet6.Cells.Item($intRowNet, 6) = $objItem.DefaultIPGateway
        $Sheet6.Cells.Item($intRowNet, 7) = $objItem.DNSServerSearchOrder
        $Sheet6.Cells.Item($intRowNet, 8) = $objItem.FullDNSRegistrationEnabled
        $Sheet6.Cells.Item($intRowNet, 9) = $objItem.WINSPrimaryServer
        $Sheet6.Cells.Item($intRowNet, 10) = $objItem.WINSSecondaryServer
        $Sheet6.Cells.Item($intRowNet, 11) = $objItem.WINSEnableLMHostsLookup
        $intRowNet = $intRowNet + 1
        }
       
$intRow = $intRow + 1
$intRowCPU = $intRowCPU + 1
$intRowMem = $intRowMem + 1
$intRowDisk = $intRowDisk + 1
$intRowNet = $intRowNet + 1
}
}

# —————————————————————————————
# Function Name ‘ListComputers’ – Enumerates ALL computer objects in AD
# —————————————————————————————
Function ListComputers {
$strCategory = "computer"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
    {$objComputer = $objResult.Properties; $objComputer.name}
}

# —————————————————————————————
# Function Name ‘ListServers’ – Enumerates ALL Servers objects in AD
# —————————————————————————————
Function ListServers {
$strCategory = "computer"
$strOS = "Windows*Server*"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(&(objectCategory=$strCategory)(OperatingSystem=$strOS))")

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
    {$objComputer = $objResult.Properties; $objComputer.name}
}

# —————————————————————————————
# Function Name ‘ListTextFile’ – Enumerates Computer Names in a text file
# Create a text file and enter the names of each computer. One computer
# name per line. Supply the path to the text file when prompted.
# —————————————————————————————
Function ListTextFile {
    $strText = Read-Host "Enter the path for the text file"
    $colComputers = Get-Content $strText
}

# —————————————————————————————
# Function Name ‘SingleEntry’ – Enumerates Computer from user input
# —————————————————————————————
Function ManualEntry {
    $colComputers = Read-Host "Enter Computer Name or IP"
}

# —————————————————————————————
# Script Body
# —————————————————————————————
$erroractionpreference = "SilentlyContinue"

#Gather info from user.
Write-Host "********************************"     -ForegroundColor Green
Write-Host "Computer Inventory Script"             -ForegroundColor Green
Write-Host "By: Jesse Hamrick"                     -ForegroundColor Green
Write-Host "Created: 04/15/2009"                 -ForegroundColor Green
Write-Host "Contact: www.PowerShellPro.com"     -ForegroundColor Green
Write-Host "********************************"     -ForegroundColor Green
Write-Host " "
Write-Host "Admin rights are required to enumerate information."     -ForegroundColor Green
Write-Host "Would you like to use an alternative credential?"        -ForegroundColor Green
$credResponse = Read-Host "[Y] Yes, [N] No"
    If($CredResponse -eq "y"){$cred = Get-Credential DOMAINUSER}
Write-Host " "
Write-Host "Which computer resources would you like in the report?"    -ForegroundColor Green
$strResponse = Read-Host "[1] All Domain Computers, [2] All Domain Servers, [3] Computer names from a File, [4] Choose a Computer manually"
If($strResponse -eq "1"){$colComputers = ListComputers | Sort-Object}
    elseif($strResponse -eq "2"){$colComputers = ListServers | Sort-Object}
    elseif($strResponse -eq "3"){. ListTextFile}
    elseif($strResponse -eq "4"){. ManualEntry}
    else{Write-Host "You did not supply a correct response, `
    Please run script again." -foregroundColor Red}               
Write-Progress -Activity "Getting Inventory" -status "Running…" -id 1

#New Excel Application
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True

# Create 6 worksheets
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()

# Assign each worksheet to a variable and
# name the worksheet.
$Sheet1 = $Excel.Worksheets.Item(1)
$Sheet2 = $Excel.WorkSheets.Item(2)
$Sheet3 = $Excel.WorkSheets.Item(3)
$Sheet4 = $Excel.WorkSheets.Item(4)
$Sheet5 = $Excel.WorkSheets.Item(5)
$Sheet6 = $Excel.WorkSheets.Item(6)
$Sheet1.Name = "General"
$Sheet2.Name = "System"
$Sheet3.Name = "Processor"
$Sheet4.Name = "Memory"
$Sheet5.Name = "Disk"
$Sheet6.Name = "Network"

#Create Heading for General Sheet
$Sheet1.Cells.Item(1,1) = "Device_Name"
$Sheet1.Cells.Item(1,2) = "Role"
$Sheet1.Cells.Item(1,3) = "HW_Make"
$Sheet1.Cells.Item(1,4) = "HW_Model"
$Sheet1.Cells.Item(1,5) = "HW_Type"
$Sheet1.Cells.Item(1,6) = "CPU_Count"
$Sheet1.Cells.Item(1,7) = "Memory_MB"
$Sheet1.Cells.Item(1,8) = "Operating_System"
$Sheet1.Cells.Item(1,9) = "SP_Level"

#Create Heading for System Sheet
$Sheet2.Cells.Item(1,1) = "Device_Name"
$Sheet2.Cells.Item(1,2) = "BIOS_Name"
$Sheet2.Cells.Item(1,3) = "BIOS_Version"
$Sheet2.Cells.Item(1,4) = "HW_Serial_#"
$Sheet2.Cells.Item(1,5) = "Time_Zone"
$Sheet2.Cells.Item(1,6) = "WMI_Version"

#Create Heading for Processor Sheet
$Sheet3.Cells.Item(1,1) = "Device_Name"
$Sheet3.Cells.Item(1,2) = "Processor(s)"
$Sheet3.Cells.Item(1,3) = "Type"
$Sheet3.Cells.Item(1,4) = "Family"
$Sheet3.Cells.Item(1,5) = "Speed_MHz"
$Sheet3.Cells.Item(1,6) = "Cache_Size_MB"
$Sheet3.Cells.Item(1,7) = "Interface"
$Sheet3.Cells.Item(1,8) = "#_of_Sockets"

#Create Heading for Memory Sheet
$Sheet4.Cells.Item(1,1) = "Device_Name"
$Sheet4.Cells.Item(1,2) = "Bank_#"
$Sheet4.Cells.Item(1,3) = "Label"
$Sheet4.Cells.Item(1,4) = "Capacity_MB"
$Sheet4.Cells.Item(1,5) = "Form"
$Sheet4.Cells.Item(1,6) = "Type"

#Create Heading for Disk Sheet
$Sheet5.Cells.Item(1,1) = "Device_Name"
$Sheet5.Cells.Item(1,2) = "Disk_Type"
$Sheet5.Cells.Item(1,3) = "Drive_Letter"
$Sheet5.Cells.Item(1,4) = "Capacity_MB"
$Sheet5.Cells.Item(1,5) = "Free_Space_MB"

#Create Heading for Network Sheet
$Sheet6.Cells.Item(1,1) = "Device_Name"
$Sheet6.Cells.Item(1,2) = "Network_Card"
$Sheet6.Cells.Item(1,3) = "DHCP_Enabled"
$Sheet6.Cells.Item(1,4) = "IP_Address"
$Sheet6.Cells.Item(1,5) = "Subnet_Mask"
$Sheet6.Cells.Item(1,6) = "Default_Gateway"
$Sheet6.Cells.Item(1,7) = "DNS_Servers"
$Sheet6.Cells.Item(1,8) = "DNS_Reg"
$Sheet6.Cells.Item(1,9) = "Primary_WINS"
$Sheet6.Cells.Item(1,10) = "Secondary_WINS"
$Sheet6.Cells.Item(1,11) = "WINS_Lookup"

$colSheets = ($Sheet1, $Sheet2, $Sheet3, $Sheet4, $Sheet5, $Sheet6)
foreach ($colorItem in $colSheets){
$intRow = 2
$intRowCPU = 2
$intRowMem = 2
$intRowDisk = 2
$intRowNet = 2
$WorkBook = $colorItem.UsedRange
$WorkBook.Interior.ColorIndex = 20
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
}

If($credResponse -eq "y"){WMILookupCred}
Else{WMILookup}

#Auto Fit all sheets in the Workbook
foreach ($colorItem in $colSheets){
$WorkBook = $colorItem.UsedRange                                                           
$WorkBook.EntireColumn.AutoFit()
clear
}
Write-Host "*******************************" -ForegroundColor Green
Write-Host "The Report has been completed."  -ForeGroundColor Green
Write-Host "*******************************" -ForegroundColor Green
# —————————————————————————————
# END of Script
# —————————————————————————————

Audit script

#############################################################################################
#                                                                                            #
#    NAME: Audit script                                                                        #
#    VERSION: 3                                                                                #
#    AUTHOR: Alan Renouf                                                                     #
#    WEB: http://virtu-al.net/                                                                #
#                                                                                            #
#    USAGE: ComputerAudit_v3_html.ps1 ‘C:pathtolistofservers’                                #
#                                                                                            #
#    COMMENT: The file is optional and needs to be a plain text list of computers to be        #
#    audited one on each line, if no list is specified the local machine will be audited.    #
#                                                                                            #
#    05-12-2011: Minor changes by Arjen Huitema                                                  #
#                                                                                             #
#############################################################################################

param( [string] $auditlist)

Function Get-CustomHTML ($Header){
$Report = @"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html><head><title>$($Header)</title>
<META http-equiv=Content-Type content=’text/html; charset=windows-1252′>

<meta name="save" content="history">

<style type="text/css">
DIV .expando {DISPLAY: block; FONT-WEIGHT: normal; FONT-SIZE: 8pt; RIGHT: 8px; COLOR: #ffffff; FONT-FAMILY: Arial; POSITION: absolute; TEXT-DECORATION: underline}
TABLE {TABLE-LAYOUT: fixed; FONT-SIZE: 100%; WIDTH: 100%}
*{margin:0}
.dspcont { display:none; BORDER-RIGHT: #B1BABF 1px solid; BORDER-TOP: #B1BABF 1px solid; PADDING-LEFT: 16px; FONT-SIZE: 8pt;MARGIN-BOTTOM: -1px; PADDING-BOTTOM: 5px; MARGIN-LEFT: 0px; BORDER-LEFT: #B1BABF 1px solid; WIDTH: 95%; COLOR: #000000; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #B1BABF 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; BACKGROUND-COLOR: #f9f9f9}
.filler {BORDER-RIGHT: medium none; BORDER-TOP: medium none; DISPLAY: block; BACKGROUND: none transparent scroll repeat 0% 0%; MARGIN-BOTTOM: -1px; FONT: 100%/8px Tahoma; MARGIN-LEFT: 43px; BORDER-LEFT: medium none; COLOR: #ffffff; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: medium none; POSITION: relative}
.save{behavior:url(#default#savehistory);}
.dspcont1{ display:none}
a.dsphead0 {BORDER-RIGHT: #B1BABF 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #B1BABF 1px solid; DISPLAY: block; PADDING-LEFT: 5px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 0px; BORDER-LEFT: #B1BABF 1px solid; CURSOR: hand; COLOR: #FFFFFF; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #B1BABF 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 2.25em; WIDTH: 95%; BACKGROUND-COLOR: #CC0000}
a.dsphead1 {BORDER-RIGHT: #B1BABF 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #B1BABF 1px solid; DISPLAY: block; PADDING-LEFT: 5px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 0px; BORDER-LEFT: #B1BABF 1px solid; CURSOR: hand; COLOR: #ffffff; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #B1BABF 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 2.25em; WIDTH: 95%; BACKGROUND-COLOR: #7BA7C7}
a.dsphead2 {BORDER-RIGHT: #B1BABF 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #B1BABF 1px solid; DISPLAY: block; PADDING-LEFT: 5px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 0px; BORDER-LEFT: #B1BABF 1px solid; CURSOR: hand; COLOR: #ffffff; MARGIN-RIGHT: 0px; PADDING-TOP: 4px; BORDER-BOTTOM: #B1BABF 1px solid; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 2.25em; WIDTH: 95%; BACKGROUND-COLOR: #7BA7C7}
a.dsphead1 span.dspchar{font-family:monospace;font-weight:normal;}
td {VERTICAL-ALIGN: TOP; FONT-FAMILY: Tahoma}
th {VERTICAL-ALIGN: TOP; COLOR: #CC0000; TEXT-ALIGN: left}
BODY {margin-left: 4pt}
BODY {margin-right: 4pt}
BODY {margin-top: 6pt}
</style>

<script type="text/javascript">
function dsp(loc){
   if(document.getElementById){
      var foc=loc.firstChild;
      foc=loc.firstChild.innerHTML?
         loc.firstChild:
         loc.firstChild.nextSibling;
      foc.innerHTML=foc.innerHTML==’hide’?’show’:’hide’;
      foc=loc.parentNode.nextSibling.style?
         loc.parentNode.nextSibling:
         loc.parentNode.nextSibling.nextSibling;
      foc.style.display=foc.style.display==’block’?’none’:’block’;}} 

if(!document.getElementById)
   document.write(‘<style type="text/css">n’+’.dspcont{display:block;}n’+ ‘</style>’);
</script>

</head>
<body>
<b><font face="Arial" size="5">$($Header)</font></b><hr size="8" color="#CC0000">
<font face="Arial" size="1"><b>Version 3 by Alan Renouf virtu-al.net</b></font><br>
<font face="Arial" size="1">Report created on $(Get-Date)</font>
<div class="filler"></div>
<div class="filler"></div>
<div class="filler"></div>
<div class="save">
"@
Return $Report
}

Function Get-CustomHeader0 ($Title){
$Report = @"
        <h1><a class="dsphead0">$($Title)</a></h1>
    <div class="filler"></div>
"@
Return $Report
}

Function Get-CustomHeader ($Num, $Title){
$Report = @"
    <h2><a href="javascript:void(0)" class="dsphead$($Num)" onclick="dsp(this)">
    <span class="expando">show</span>$($Title)</a></h2>
    <div class="dspcont">
"@
Return $Report
}

Function Get-CustomHeaderClose{

    $Report = @"
        </DIV>
        <div class="filler"></div>
"@
Return $Report
}

Function Get-CustomHeader0Close{

    $Report = @"
</DIV>
"@
Return $Report
}

Function Get-CustomHTMLClose{

    $Report = @"
</div>

</body>
</html>
"@
Return $Report
}

Function Get-HTMLTable{
    param([array]$Content)
    $HTMLTable = $Content | ConvertTo-Html
    $HTMLTable = $HTMLTable -replace ‘<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">’, ""
    $HTMLTable = $HTMLTable -replace ‘<html xmlns="http://www.w3.org/1999/xhtml">’, ""
    $HTMLTable = $HTMLTable -replace ‘<head>’, ""
    $HTMLTable = $HTMLTable -replace ‘<title>HTML TABLE</title>’, ""
    $HTMLTable = $HTMLTable -replace ‘</head><body>’, ""
    $HTMLTable = $HTMLTable -replace ‘</body></html>’, ""
    Return $HTMLTable
}

Function Get-HTMLDetail ($Heading, $Detail){
$Report = @"
<TABLE>
    <tr>
    <th width=’25%’><b>$Heading</b></font></th>
    <td width=’75%’>$($Detail)</td>
    </tr>
</TABLE>
"@
Return $Report
}

if ($auditlist -eq ""){
    Write-Host "No list specified, using $env:computername"
    $targets = $env:computername
}
else
{
    if ((Test-Path $auditlist) -eq $false)
    {
        Write-Host "Invalid audit path specified: $auditlist"
        exit
    }
    else
    {
        Write-Host "Using Audit list: $auditlist"
        $Targets = Get-Content $auditlist
    }
}

Foreach ($Target in $Targets){

Write-Output "Collating Detail for $Target"
    $ComputerSystem = Get-WmiObject -computername $Target Win32_ComputerSystem
    switch ($ComputerSystem.DomainRole){
        0 { $ComputerRole = "Standalone Workstation" }
        1 { $ComputerRole = "Member Workstation" }
        2 { $ComputerRole = "Standalone Server" }
        3 { $ComputerRole = "Member Server" }
        4 { $ComputerRole = "Domain Controller" }
        5 { $ComputerRole = "Domain Controller" }
        default { $ComputerRole = "Information not available" }
    }
   
    $OperatingSystems = Get-WmiObject -computername $Target Win32_OperatingSystem
    $TimeZone = Get-WmiObject -computername $Target Win32_Timezone
    $Keyboards = Get-WmiObject -computername $Target Win32_Keyboard
    $SchedTasks = Get-WmiObject -computername $Target Win32_ScheduledJob
    $BootINI = $OperatingSystems.SystemDrive + "boot.ini"
    $RecoveryOptions = Get-WmiObject -computername $Target Win32_OSRecoveryConfiguration
   
    switch ($ComputerRole){
        "Member Workstation" { $CompType = "Computer Domain"; break }
        "Domain Controller" { $CompType = "Computer Domain"; break }
        "Member Server" { $CompType = "Computer Domain"; break }
        default { $CompType = "Computer Workgroup"; break }
    }

    $LBTime=$OperatingSystems.ConvertToDateTime($OperatingSystems.Lastbootuptime)
    Write-Output "..Regional Options"
    $ObjKeyboards = Get-WmiObject -ComputerName $Target Win32_Keyboard
    $keyboardmap = @{
    "00000402" = "BG"
    "00000404" = "CH"
    "00000405" = "CZ"
    "00000406" = "DK"
    "00000407" = "GR"
    "00000408" = "GK"
    "00000409" = "US"
    "0000040A" = "SP"
    "0000040B" = "SU"
    "0000040C" = "FR"
    "0000040E" = "HU"
    "0000040F" = "IS"
    "00000410" = "IT"
    "00000411" = "JP"
    "00000412" = "KO"
    "00000413" = "NL"
    "00000414" = "NO"
    "00000415" = "PL"
    "00000416" = "BR"
    "00000418" = "RO"
    "00000419" = "RU"
    "0000041A" = "YU"
    "0000041B" = "SL"
    "0000041C" = "US"
    "0000041D" = "SV"
    "0000041F" = "TR"
    "00000422" = "US"
    "00000423" = "US"
    "00000424" = "YU"
    "00000425" = "ET"
    "00000426" = "US"
    "00000427" = "US"
    "00000804" = "CH"
    "00000809" = "UK"
    "0000080A" = "LA"
    "0000080C" = "BE"
    "00000813" = "BE"
    "00000816" = "PO"
    "00000C0C" = "CF"
    "00000C1A" = "US"
    "00001009" = "US"
    "0000100C" = "SF"
    "00001809" = "US"
    "00010402" = "US"
    "00010405" = "CZ"
    "00010407" = "GR"
    "00010408" = "GK"
    "00010409" = "DV"
    "0001040A" = "SP"
    "0001040E" = "HU"
    "00010410" = "IT"
    "00010415" = "PL"
    "00010419" = "RU"
    "0001041B" = "SL"
    "0001041F" = "TR"
    "00010426" = "US"
    "00010C0C" = "CF"
    "00010C1A" = "US"
    "00020408" = "GK"
    "00020409" = "US"
    "00030409" = "USL"
    "00040409" = "USR"
    "00050408" = "GK"
    }
    $keyb = $keyboardmap.$($ObjKeyboards.Layout)
    if (!$keyb)
    { $keyb = "Unknown"
    }
    $MyReport = Get-CustomHTML "$Target Audit"
    $MyReport += Get-CustomHeader0  "$Target Details"
    $MyReport += Get-CustomHeader "2" "General"
        $MyReport += Get-HTMLDetail "Computer Name" ($ComputerSystem.Name)
        $MyReport += Get-HTMLDetail "Computer Role" ($ComputerRole)
        $MyReport += Get-HTMLDetail $CompType ($ComputerSystem.Domain)
        $MyReport += Get-HTMLDetail "Operating System" ($OperatingSystems.Caption)
        $MyReport += Get-HTMLDetail "Service Pack" ($OperatingSystems.CSDVersion)
        $MyReport += Get-HTMLDetail "System Root" ($OperatingSystems.SystemDrive)
        $MyReport += Get-HTMLDetail "Manufacturer" ($ComputerSystem.Manufacturer)
        $MyReport += Get-HTMLDetail "Model" ($ComputerSystem.Model)
        $MyReport += Get-HTMLDetail "Number of Processors" ($ComputerSystem.NumberOfProcessors)
        $MyReport += Get-HTMLDetail "Memory" ($ComputerSystem.TotalPhysicalMemory)
        $MyReport += Get-HTMLDetail "Registered User" ($ComputerSystem.PrimaryOwnerName)
        $MyReport += Get-HTMLDetail "Registered Organisation" ($OperatingSystems.Organization)
        $MyReport += Get-HTMLDetail "Last System Boot" ($LBTime)
        $MyReport += Get-CustomHeaderClose
        Write-Output "..Hotfix Information"
        $colQuickFixes = Get-WmiObject Win32_QuickFixEngineering
        $MyReport += Get-CustomHeader "2" "HotFixes"
            $MyReport += Get-HTMLTable ($colQuickFixes | Where {$_.HotFixID -ne "File 1" } |Select HotFixID, Description)
        $MyReport += Get-CustomHeaderClose
        Write-Output "..Logical Disks"
        $Disks = Get-WmiObject -ComputerName $Target Win32_LogicalDisk
        $MyReport += Get-CustomHeader "2" "Logical Disk Configuration"
            $LogicalDrives = @()
            Foreach ($LDrive in ($Disks | Where {$_.DriveType -eq 3})){
                $Details = "" | Select "Drive Letter", Label, "File System", "Disk Size (MB)", "Disk Free Space", "% Free Space"
                $Details."Drive Letter" = $LDrive.DeviceID
                $Details.Label = $LDrive.VolumeName
                $Details."File System" = $LDrive.FileSystem
                $Details."Disk Size (MB)" = [math]::round(($LDrive.size / 1MB))
                $Details."Disk Free Space" = [math]::round(($LDrive.FreeSpace / 1MB))
                $Details."% Free Space" = [Math]::Round(($LDrive.FreeSpace /1MB) / ($LDrive.Size / 1MB) * 100)
                $LogicalDrives += $Details
            }
            $MyReport += Get-HTMLTable ($LogicalDrives)
        $MyReport += Get-CustomHeaderClose
        Write-Output "..Network Configuration"
        $Adapters = Get-WmiObject -ComputerName $Target Win32_NetworkAdapterConfiguration
        $MyReport += Get-CustomHeader "2" "NIC Configuration"
            $IPInfo = @()
            Foreach ($Adapter in ($Adapters | Where {$_.IPEnabled -eq $True})) {
                $Details = "" | Select Description, "Physical address", "IP Address / Subnet Mask", "Default Gateway", "DHCP Enabled", DNS, WINS
                $Details.Description = "$($Adapter.Description)"
                $Details."Physical address" = "$($Adapter.MACaddress)"
                If ($Adapter.IPAddress -ne $Null) {
                $Details."IP Address / Subnet Mask" = "$($Adapter.IPAddress)/$($Adapter.IPSubnet)"
                    $Details."Default Gateway" = "$($Adapter.DefaultIPGateway)"
                }
                If ($Adapter.DHCPEnabled -eq "True")    {
                    $Details."DHCP Enabled" = "Yes"
                }
                Else {
                    $Details."DHCP Enabled" = "No"
                }
                If ($Adapter.DNSServerSearchOrder -ne $Null)    {
                    $Details.DNS =  "$($Adapter.DNSServerSearchOrder)"
                }
                $Details.WINS = "$($Adapter.WINSPrimaryServer) $($Adapter.WINSSecondaryServer)"
                $IPInfo += $Details
            }
            $MyReport += Get-HTMLTable ($IPInfo)
        $MyReport += Get-CustomHeaderClose
        If ((get-wmiobject -ComputerName $Target -namespace "root/cimv2" -list) | Where-Object {$_.name -match "Win32_Product"})
        {
            Write-Output "..Software"
            $MyReport += Get-CustomHeader "2" "Software"
                $MyReport += Get-HTMLTable (get-wmiobject -ComputerName $Target Win32_Product | select Name,Version,Vendor,InstallDate)
            $MyReport += Get-CustomHeaderClose
        }
        Else {
            Write-Output "..Software WMI class not installed"
        }
        Write-Output "..Local Shares"
        $Shares = Get-wmiobject -ComputerName $Target Win32_Share
        $MyReport += Get-CustomHeader "2" "Local Shares"
            $MyReport += Get-HTMLTable ($Shares | Select Name, Path, Caption)
        $MyReport += Get-CustomHeaderClose
        Write-Output "..Printers"
        $InstalledPrinters =  Get-WmiObject -ComputerName $Target Win32_Printer
        $MyReport += Get-CustomHeader "2" "Printers"
            $MyReport += Get-HTMLTable ($InstalledPrinters | Select Name, Location)
        $MyReport += Get-CustomHeaderClose
        Write-Output "..Services"
        $ListOfServices = Get-WmiObject -ComputerName $Target Win32_Service
        $MyReport += Get-CustomHeader "2" "Services"
            $Services = @()
            Foreach ($Service in $ListOfServices){
                $Details = "" | Select Name,Account,"Start Mode",State,"Expected State"
                $Details.Name = $Service.Caption
                $Details.Account = $Service.Startname
                $Details."Start Mode" = $Service.StartMode
                If ($Service.StartMode -eq "Auto")
                    {
                        if ($Service.State -eq "Stopped")
                        {
                            $Details.State = $Service.State
                            $Details."Expected State" = "Unexpected"
                        }
                    }
                    If ($Service.StartMode -eq "Auto")
                    {
                        if ($Service.State -eq "Running")
                        {
                            $Details.State = $Service.State
                            $Details."Expected State" = "OK"
                        }
                    }
                    If ($Service.StartMode -eq "Disabled")
                    {
                        If ($Service.State -eq "Running")
                        {
                            $Details.State = $Service.State
                            $Details."Expected State" = "Unexpected"
                        }
                    }
                    If ($Service.StartMode -eq "Disabled")
                    {
                        if ($Service.State -eq "Stopped")
                        {
                            $Details.State = $Service.State
                            $Details."Expected State" = "OK"
                        }
                    }
                    If ($Service.StartMode -eq "Manual")
                    {
                        $Details.State = $Service.State
                        $Details."Expected State" = "OK"
                    }
                    If ($Service.State -eq "Paused")
                    {
                        $Details.State = $Service.State
                        $Details."Expected State" = "OK"
                    }
                $Services += $Details
            }
            $MyReport += Get-HTMLTable ($Services)
        $MyReport += Get-CustomHeaderClose
        $MyReport += Get-CustomHeader "2" "Regional Settings"
            $MyReport += Get-HTMLDetail "Time Zone" ($TimeZone.Description)
            $MyReport += Get-HTMLDetail "Country Code" ($OperatingSystems.Countrycode)
            $MyReport += Get-HTMLDetail "Locale" ($OperatingSystems.Locale)
            $MyReport += Get-HTMLDetail "Operating System Language" ($OperatingSystems.OSLanguage)
            $MyReport += Get-HTMLDetail "Keyboard Layout" ($keyb)
        $MyReport += Get-CustomHeaderClose
        Write-Output "..Event Log Settings"
        $LogFiles = Get-WmiObject -ComputerName $Target Win32_NTEventLogFile
        $MyReport += Get-CustomHeader "2" "Event Logs"
            $MyReport += Get-CustomHeader "2" "Event Log Settings"
            $LogSettings = @()
            Foreach ($Log in $LogFiles){
                $Details = "" | Select "Log Name", "Overwrite Outdated Records", "Maximum Size (KB)", "Current Size (KB)"
                $Details."Log Name" = $Log.LogFileName
                If ($Log.OverWriteOutdated -lt 0)
                    {
                        $Details."Overwrite Outdated Records" = "Never"
                    }
                if ($Log.OverWriteOutdated -eq 0)
                {
                    $Details."Overwrite Outdated Records" = "As needed"
                }
                Else
                {
                    $Details."Overwrite Outdated Records" = "After $($Log.OverWriteOutdated) days"
                }
                $MaxFileSize = ($Log.MaxFileSize) / 1024
                $FileSize = ($Log.FileSize) / 1024
               
                $Details."Maximum Size (KB)" = $MaxFileSize
                $Details."Current Size (KB)" = $FileSize
                $LogSettings += $Details
            }
            $MyReport += Get-HTMLTable ($LogSettings)
            $MyReport += Get-CustomHeaderClose
            Write-Output "..Event Log Errors"
            $WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-14))
            $LoggedErrors = Get-WmiObject -computer $Target -query ("Select * from Win32_NTLogEvent Where Type=’Error’ and TimeWritten >=’" + $WmidtQueryDT + "’")
            $MyReport += Get-CustomHeader "2" "ERROR Entries"
                $MyReport += Get-HTMLTable ($LoggedErrors | Select EventCode, SourceName, @{N="Time";E={$_.ConvertToDateTime($_.TimeWritten)}}, LogFile, Message)
            $MyReport += Get-CustomHeaderClose
            Write-Output "..Event Log Warnings"
            $WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-14))
            $LoggedWarning = Get-WmiObject -computer $Target -query ("Select * from Win32_NTLogEvent Where Type=’Warning’ and TimeWritten >=’" + $WmidtQueryDT + "’")
            $MyReport += Get-CustomHeader "2" "WARNING Entries"
                $MyReport += Get-HTMLTable ($LoggedWarning | Select EventCode, SourceName, @{N="Time";E={$_.ConvertToDateTime($_.TimeWritten)}}, LogFile, Message)
            $MyReport += Get-CustomHeaderClose
        $MyReport += Get-CustomHeaderClose
        $MyReport += Get-CustomHeaderClose
    $MyReport += Get-CustomHeader0Close
    $MyReport += Get-CustomHTMLClose
    $MyReport += Get-CustomHTMLClose

    $Date = Get-Date
    $Filename = "." + $Target + "_" + $date.Hour + $date.Minute + "_" + $Date.Day + "-" + $Date.Month + "-" + $Date.Year + ".htm"
    $MyReport | out-file -encoding ASCII -filepath $Filename
    Write "Audit saved as $Filename"
}