Script to include error checking

This topic contains 6 replies, has 2 voices, and was last updated by Profile photo of Hiten Mandalia Hiten Mandalia 2 years, 2 months ago.

  • Author
    Posts
  • #18170
    Profile photo of Hiten Mandalia
    Hiten Mandalia
    Participant

    Hi All,
    Hopefully someone can help me with this. I'm quite new to powershell and dont really know much about it. A bit of background on what i want to achieve.
    At the end of each server build (vm or physical), I would like to run a script which does a full inventory of our windows servers and checks for anything which is not configured / installed. So for example once the server is build, I would like to check what windows features are installed / GPO's are applied / windows activation status etc and then i want the script to create a HTML report and highlight anything it finds which could be missing or not configured. I understand this is quite vague but for the time being i would just like a generic check and then can fine tune it later. I have managed to get the following script from another site and added a few modifications myself but need to now get it doing what i want:

    Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue 
    
    $UserName = (Get-Item  env:\username).Value
    $ComputerName = (Get-Item env:\Computername).Value 
    #$filepath = (Get-ChildItem env:\userprofile).value
    $share = "\\files\general$\Operations\Build Reports"
    
    #ReportDate 
    $ReportDate = Get-Date | Select -Property DateTime |ConvertTo-Html -Fragment 
    
    #General Information 
    $ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem |  
    Select -Property Model , Manufacturer , Description , PrimaryOwnerName , SystemType |ConvertTo-Html -Fragment 
    
    #Operating System Information 
    $OS = Get-WmiObject -Class Win32_OperatingSystem | Select -Property Caption , CSDVersion , OSArchitecture , OSLanguage | ConvertTo-Html -Fragment 
    
    #Windows Activation Status
    $Activation = Get-CimInstance -ClassName SoftwareLicensingProduct | where PartialProductKey | Select Name, @{Label="Grace period (days)"; Expression={ $_.graceperiodremaining / 1440}}, @{Label= "License Status"; Expression={switch (foreach {$_.LicenseStatus}) { 0 {"Unlicensed"} 1 {"Licensed"} 2 {"Out-Of-Box Grace Period"} 3 {"Out-Of-Tolerance Grace Period"} 4 {"Non-Genuine Grace Period"} 5 {"Notification Period"} 6 {"Extended Grace"} } } } | ConvertTo-Html -Fragment 
    
    #Logical Disk Information 
    $Disk = Get-WmiObject -Class Win32_LogicalDisk -Filter DriveType=3 | 
    Select SystemName , DeviceID , @{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}}, @{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}} | 
    ConvertTo-Html -Fragment 
    
    #Time Zone Information 
    $TimeZone = Get-WmiObject -Class Win32_TimeZone | Select Caption , StandardName | ConvertTo-Html -Fragment 
    
    #CPU Information 
    $SystemProcessor = Get-WmiObject -Class Win32_Processor  |  Select SystemName , Name , MaxClockSpeed , Manufacturer , status |ConvertTo-Html -Fragment
    
    #Memory Information 
    $PhysicalMemory = Get-WmiObject -Class Win32_PhysicalMemory | Select -Property Tag , SerialNumber , PartNumber , Manufacturer , DeviceLocator , @{Name="Capacity(GB)";Expression={"{0:N1}" -f ($_.Capacity/1GB)}} | ConvertTo-Html -Fragment 
    
    #Software Inventory 
    $Software = Get-WmiObject -Class Win32_Product | Select Name , Vendor , Version , Caption | ConvertTo-Html -Fragment  
    
    #Windows Features Inventory
    $Features = Get-WmiObject -query "select * from win32_optionalfeature where installstate=1" | select Name, Caption | ConvertTo-Html -Fragment
    
    ConvertTo-Html -Body "Report Executed On$ReportDate 
    Report Generated By$username
    General Information$ComputerSystem 
    Operating System Information$OS 
    Activation Status$Activation
    Time Zone Information$TimeZone 
    Disk Information$Disk 
    Processor Information$SystemProcessor 
    Memory Information$PhysicalMemory 
    Windows Features Iventory$Features
    Software Inventory$Software" -CssUri  "$share\style.CSS" -Title "Server Inventory" | Out-File "$share\$ComputerName.html" 
    
    Write-Host "Script Execution Completed" -ForegroundColor Yellow 
    Invoke-Item -Path "$share\$ComputerName.html"
    

    So what I would like is in the HTML report, anything that is not done right is highlighted in Red with a quick sentence at the end stating the issue. So for example where this script checks the Windows Activation status, I would like that any status which is reported that is not "Licensed" is highlighted red in the HTML report and a sentence at the end of the report which reads out something like "Windows is not activated. Please activate". All our base build have a certain set of windows features installed, so the script could reference a set of features installed on a current system (possibly output the windows features from a correctly built system which is output to a file and then compared on the newly built server) and check what is missing and again highlight in red (for example "Failover clustering is not Installed" etc.
    I would appreciate any help that could be provided
    Thanks

  • #18171
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, that's a lot!

    First, on the Resources menu, you'll find several free ebooks that address these topics, including building HTML reports and error handling. You might want to start there.

    But, if you have a specific question, happy to try and answer it. I realize you may have several questions, but it's often easiest to just do one at a time.

  • #18175
    Profile photo of Hiten Mandalia
    Hiten Mandalia
    Participant

    Hi Don,

    Thanks for your reply. I am looking through the guide right now.

    Im sorry if I am asking silly questions but as a total newbie to powershell (even scripting for that matter ) i dont really know how to start. This script is something i pulled off the web and just added some changes. It works well and creates the report.
    What I need to do now, is add that "part" which does the checks and highlights them if it "failed" or what i deem to be a failure.

    So for example, the above script reports on the activation status of windows.

    #Windows Activation Status
    $Activation = Get-CimInstance -ClassName SoftwareLicensingProduct | where PartialProductKey | Select Name, @{Label="Grace period (days)"; Expression={ $_.graceperiodremaining / 1440}}, @{Label= "License Status"; Expression={switch (foreach {$_.LicenseStatus}) { 0 {"Unlicensed"} 1 {"Licensed"} 2 {"Out-Of-Box Grace Period"} 3 {"Out-Of-Tolerance Grace Period"} 4 {"Non-Genuine Grace Period"} 5 {"Notification Period"} 6 {"Extended Grace"} } } } | ConvertTo-Html -Fragment 
    

    It then puts it in the HTML report: (sorry I cant seem to get the HTML code to correctly display because this keeps getting converted)

    ConvertTo-Html -Body "Report Executed On$ReportDate 
    Report Generated By$username
    General Information$ComputerSystem 
    Operating System Information$OS 
    Activation Status$Activation
    Time Zone Information$TimeZone 
    Disk Information$Disk 
    Processor Information$SystemProcessor 
    Memory Information$PhysicalMemory 
    Windows Features Iventory$Features
    Software Inventory$Software" -CssUri  "$share\style.CSS" -Title "Server Inventory" | Out-File "$share\$ComputerName.html" 
    

    What I would like is if windows is correctly licensed and activated then it continues to display on a blue background as it currently does. But if the licensed / activation state is anything else, then it would highlight in red so it easily picked up (hope that makes some sense).

    I think if I can get this one part working then i should find it easier to apply that to the other parts of the report.

    I have also posted this on [url]http://community.spiceworks.com/topic/565041-script-to-include-error-checking-in-powershell[/url] so you can check the code with the HTML stuff if need be

  • #18178
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Definitely look at "Creating HTML Reports in PowerShell" as a start. For one, you ideally want to feed an object to ConvertTo-HTML, not a block of text. In terms of formatting, that's really an HTML question, not PowerShell. HTML will let you define a class in your CSS, and that class can specify an alternate color, but you have to apply that class to an HTML tag that surrounds the text you want colored. The ebook provides a replacement Set of HTML cmdlets to help do all of that, but they're designed to work with objects rather than text. The examples in the book are fairly straightforward, so hopefully that'll help,you pick up the pattern. There is a specific example of coloring a table cell based on the contents of that cell, which is basically what you're wanting to do.

  • #18335
    Profile photo of Hiten Mandalia
    Hiten Mandalia
    Participant

    OK, i think I have a script doing what I want to do in some sense and was wondering if you can help me with the next part of this. Heres the code I have so far (its your code which i have amended)

    $UserName = (Get-Item  env:\username).Value
    $ComputerName = (Get-Item env:\Computername).Value
    $Path = "\\files\general$\operations\Build Reports"
    
    
    $style = @"
    
    body {
        color:#333333;
        font-family:Calibri,Tahoma;
        font-size: 10pt;
    }
    h1 {
        text-align:center;
    }
    h2 {
        border-top:1px solid #666666;
    }
    
    th {
        font-weight:bold;
        color:#eeeeee;
        background-color:#333333;
        cursor:pointer;
    }
    .odd  { background-color:#ffffff; }
    .even { background-color:#dddddd; }
    .paginate_enabled_next, .paginate_enabled_previous {
        cursor:pointer; 
        border:1px solid #222222; 
        background-color:#dddddd; 
        padding:2px; 
        margin:4px;
        border-radius:2px;
    }
    .paginate_disabled_previous, .paginate_disabled_next {
        color:#666666; 
        cursor:pointer;
        background-color:#dddddd; 
        padding:2px; 
        margin:4px;
        border-radius:2px;
    }
    .dataTables_info { margin-bottom:4px; }
    .sectionheader { cursor:pointer; }
    .sectionheader:hover { color:red; }
    .grid { width:100% }
    .red {
        color:red;
        font-weight:bold;
    } 
    .yellow {
    	color:yellow;
    	font-weight:bold;
    } 
    .green {
    	color:green;
    	font-weight:bold;
    }
    
    "@
    
    function Get-InfoOS {
        $os = Get-WmiObject -class Win32_OperatingSystem -ComputerName $ComputerName
        $props = @{'OS Version'=$os.caption;
    }
        New-Object -TypeName PSObject -Property $props
    }
    
    function Get-TimeZone{
        $tz = Get-WmiObject -class Win32_TimeZone -ComputerName $ComputerName
        $props = @{'TimeZone'=$tz.caption;
    }
        New-Object -TypeName PSObject -Property $props
    }
    
    function Get-ActivationStatus {
            try {
                $wpa = Get-WmiObject SoftwareLicensingProduct -ComputerName $ComputerName `
                -Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" `
                -Property LicenseStatus -ErrorAction Stop
            } catch {
                $status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode)
                $wpa = $null    
            }
            $out = New-Object psobject -Property @{
                ComputerName = $ComputerName;
                Status = [string]::Empty;
            }
            if ($wpa) {
                :outer foreach($item in $wpa) {
                    switch ($item.LicenseStatus) {
                        0 {$out.Status = "Unlicensed"}
                        1 {$out.Status = "Licensed"; break outer}
                        2 {$out.Status = "Out-Of-Box Grace Period"; break outer}
                        3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer}
                        4 {$out.Status = "Non-Genuine Grace Period"; break outer}
                        5 {$out.Status = "Notification"; break outer}
                        6 {$out.Status = "Extended Grace"; break outer}
                        default {$out.Status = "Unknown value"}
                    }
                }
            } else {$out.Status = $status.Message}
            $out
        }
    	
    function Get-InfoCompSystem {
        $cs = Get-WmiObject -class Win32_ComputerSystem -ComputerName $ComputerName
        $props = @{'Model'=$cs.model;
                   'Manufacturer'=$cs.manufacturer;
                   'RAM (GB)'="{0:N2}" -f ($cs.totalphysicalmemory / 1GB);
                   'Sockets'=$cs.numberofprocessors;
                   'Cores'=$cs.numberoflogicalprocessors}
        New-Object -TypeName PSObject -Property $props
    }
    
    function Get-InfoBadService {
        $svcs = Get-WmiObject -class Win32_Service -ComputerName $ComputerName `
               -Filter "StartMode='Auto' AND State'Running'"
        foreach ($svc in $svcs) {
            $props = @{'ServiceName'=$svc.name;
                       'LogonAccount'=$svc.startname;
                       'DisplayName'=$svc.displayname}
            New-Object -TypeName PSObject -Property $props
        }
    }
    
    function Get-InfoNIC {
        $nics = Get-WmiObject -class Win32_NetworkAdapter -ComputerName $ComputerName `
               -Filter "PhysicalAdapter=True"
        foreach ($nic in $nics) {      
            $props = @{'NICName'=$nic.servicename;
                       'Speed'=$nic.speed / 1GB -as [int];
                       'Manufacturer'=$nic.manufacturer;
                       'MACAddress'=$nic.macaddress}
            New-Object -TypeName PSObject -Property $props
        }
    }
    
    function Get-InfoDisk {
        $drives = Get-WmiObject -class Win32_LogicalDisk -ComputerName $ComputerName `
               -Filter "DriveType=3"
        foreach ($drive in $drives) {      
            $props = @{'Drive'=$drive.DeviceID;
                       'Size'=$drive.size / 1GB -as [int];
                       'Free'="{0:N2}" -f ($drive.freespace / 1GB);
                       'FreePct'=$drive.freespace / $drive.size * 100 -as [int]}
            New-Object -TypeName PSObject -Property $props 
        }
    }
    
            $filepath = Join-Path -Path $Path -ChildPath "$computername.html"
    
            $params = @{'As'='Table';
                        'PreContent'='OS'}
    					
            $html_os = Get-InfoOS -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    	
         	$params	= @{'As'='List';
    					'PreContent'='Time Zone'
    					'Properties'= @{n='Time Zone';e={$_.TimeZone};css={if ($_.TimeZone -eq '(UTC) Co-ordinated Universal Time') { 'green' } else { 'red' }}}}
    		
    		$html_tz =  Get-TimeZone -ComputerName $computer |
    					ConvertTo-EnhancedHTMLFragment @params
    		
            $params = @{'As'='List';
                        'PreContent'='Computer System'}
    					
            $html_cs = Get-InfoCompSystem -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    			  
            $params = @{'As'='Table';
                        'PreContent'='Activation Status';
    					'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'TableCssClass'='grid';
    					'Properties'='ComputerName',
    							@{n='Status';e={$_.status};css={if ($_.status -eq 'Licensed') { 'green' } elseif ($_.status -eq 'Out-Of-Box Grace Period', 'Notification', 'Extended Grace', 'Out-Of-Tolerance Grace Period', 'Non-Genuine Grace Period') { 'yellow' } else { 'red' }}}}
    
            $html_as = Get-ActivationStatus -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    
            $params = @{'As'='Table';
                        'PreContent'='Local Disks';
                        'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'MakeTableDynamic'=$true;
                        'TableCssClass'='grid';
                        'Properties'='Drive',
                                     @{n='Size(GB)';e={$_.Size}},
                                     @{n='Free(GB)';e={$_.Free}},
                                     @{n='Free(%)';e={$_.FreePct};css={if ($_.FreePct -lt 10) { 'red' } elseif ($_.FreePct -lt 75) { 'yellow' } else { 'green' }}}}
    								 
            $html_dr = Get-InfoDisk -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params
    
            $params = @{'As'='Table';
                        'PreContent'='Services to CheckThe following services are set to Automatic Start but have not started';
                        'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'TableCssClass'='grid'}
    					
            $html_sv = Get-InfoBadService -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    
            $params = @{'As'='Table';
                        'PreContent'='NICs';
                        'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'TableCssClass'='grid'}
    					
            $html_na = Get-InfoNIC -ComputerName $Computer |
                       ConvertTo-EnhancedHTMLFragment @params
    
    
            $params = @{'CssStyleSheet'=$style;
                        'Title'="System Report for $computername";
                        'PreContent'="System Report for $computernameReport Generated by $UserName";
                        'HTMLFragments'=@($html_os,$html_tz,$html_cs,$html_as,$html_dr,$html_sv,$html_na)
                        } 
    					
            ConvertTo-EnhancedHTML @params |
            Out-File -FilePath $filepath
    		invoke-item -Path $filepath
    

    What I would like to do is add a compare to this code. I have a text file in the same directory as this script which has a list of Windows Features which should be installed on the newly built system. I would like to add a process to this code which will load the txt file and compare it to the features that are installed on the new system and highlight / list in the HTML report any features which it finds are not installed.

    Would you be able to help?

  • #18341
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Use Compare-Object. Although the CliXML format would probably be better, text should work okay for this.

  • #18682
    Profile photo of Hiten Mandalia
    Hiten Mandalia
    Participant
    #requires -module EnhancedHTML2
    
    $UserName = (Get-Item  env:\username).Value
    $ComputerName = (Get-Item env:\Computername).Value
    $Path = "\\files\general$\operations\Build Reports"
    
    
    $style = @"
    
    body {
        color:#333333;
        font-family:Calibri,Tahoma;
        font-size: 10pt;
    }
    h1 {
        text-align:center;
    }
    h2 {
        border-top:1px solid #666666;
    }
    
    th {
        font-weight:bold;
        color:#eeeeee;
        background-color:#333333;
        cursor:pointer;
    }
    .odd  { background-color:#ffffff; }
    .even { background-color:#dddddd; }
    .paginate_enabled_next, .paginate_enabled_previous {
        cursor:pointer; 
        border:1px solid #222222; 
        background-color:#dddddd; 
        padding:2px; 
        margin:4px;
        border-radius:2px;
    }
    .paginate_disabled_previous, .paginate_disabled_next {
        color:#666666; 
        cursor:pointer;
        background-color:#dddddd; 
        padding:2px; 
        margin:4px;
        border-radius:2px;
    }
    .dataTables_info { margin-bottom:4px; }
    .sectionheader { cursor:pointer; }
    .sectionheader:hover { color:red; }
    .grid { width:100% }
    .red {
        color:red;
        font-weight:bold;
    } 
    .yellow {
    	color:yellow;
    	font-weight:bold;
    } 
    .green {
    	color:green;
    	font-weight:bold;
    }
    
    "@
    
    function Get-InfoOS {
        $os = Get-WmiObject -class Win32_OperatingSystem -ComputerName $ComputerName
        $props = @{'OS Version'=$os.caption;
    }
        New-Object -TypeName PSObject -Property $props
    }
    
    function Get-TimeZone{
        $tz = Get-WmiObject -class Win32_TimeZone -ComputerName $ComputerName
        $props = @{'TimeZone'=$tz.caption;
    }
        New-Object -TypeName PSObject -Property $props
    }
    
    function Get-ActivationStatus {
            try {
                $wpa = Get-WmiObject SoftwareLicensingProduct -ComputerName $ComputerName `
                -Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" `
                -Property LicenseStatus -ErrorAction Stop
            } catch {
                $status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode)
                $wpa = $null    
            }
            $out = New-Object psobject -Property @{
                ComputerName = $ComputerName;
                Status = [string]::Empty;
            }
            if ($wpa) {
                :outer foreach($item in $wpa) {
                    switch ($item.LicenseStatus) {
                        0 {$out.Status = "Unlicensed"}
                        1 {$out.Status = "Licensed"; break outer}
                        2 {$out.Status = "Out-Of-Box Grace Period"; break outer}
                        3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer}
                        4 {$out.Status = "Non-Genuine Grace Period"; break outer}
                        5 {$out.Status = "Notification"; break outer}
                        6 {$out.Status = "Extended Grace"; break outer}
                        default {$out.Status = "Unknown value"}
                    }
                }
            } else {$out.Status = $status.Message}
            $out
        }
    	
    function Get-InfoCompSystem {
        $cs = Get-WmiObject -class Win32_ComputerSystem -ComputerName $ComputerName
        $props = @{'Model'=$cs.model;
                   'Manufacturer'=$cs.manufacturer;
                   'RAM (GB)'="{0:N2}" -f ($cs.totalphysicalmemory / 1GB);
                   'Sockets'=$cs.numberofprocessors;
                   'Cores'=$cs.numberoflogicalprocessors}
        New-Object -TypeName PSObject -Property $props
    }
    
    function Get-InstalledFeatures {
    	Get-WmiObject -class Win32_OptionalFeature `
    			-Filter "InstallState = '1'" | fl Caption > C:\Windows\Betgenius.Ops\featuresinstalled.txt
    
    	$a = Get-Content C:\Windows\Betgenius.Ops\features.txt
    	$b = Get-Content C:\Windows\Betgenius.Ops\featuresinstalled.txt
    	$diff = compare-object -referenceobject $a -differenceobject $b
    	foreach ($feature in $diff) {
    		$props = @ {'Feature'=$feature}
    	new-object -TypeName PSObject -Property $props
    	
    }
    
    function Get-InfoBadService {
        $svcs = Get-WmiObject -class Win32_Service -ComputerName $ComputerName `
               -Filter "StartMode='Auto' AND State'Running'"
        foreach ($svc in $svcs) {
            $props = @{'ServiceName'=$svc.name;
                       'LogonAccount'=$svc.startname;
                       'DisplayName'=$svc.displayname}
            New-Object -TypeName PSObject -Property $props
        }
    }
    
    function Get-InfoNIC {
        $nics = Get-WmiObject -class Win32_NetworkAdapter -ComputerName $ComputerName `
               -Filter "PhysicalAdapter=True"
        foreach ($nic in $nics) {      
            $props = @{'NICName'=$nic.servicename;
                       'Speed'=$nic.speed / 1GB -as [int];
                       'Manufacturer'=$nic.manufacturer;
                       'MACAddress'=$nic.macaddress}
            New-Object -TypeName PSObject -Property $props
        }
    }
    
    function Get-InfoDisk {
        $drives = Get-WmiObject -class Win32_LogicalDisk -ComputerName $ComputerName `
               -Filter "DriveType=3"
        foreach ($drive in $drives) {      
            $props = @{'Drive'=$drive.DeviceID;
                       'Size'=$drive.size / 1GB -as [int];
                       'Free'="{0:N2}" -f ($drive.freespace / 1GB);
                       'FreePct'=$drive.freespace / $drive.size * 100 -as [int]}
            New-Object -TypeName PSObject -Property $props 
        }
    }
    
            $filepath = Join-Path -Path $Path -ChildPath "$computername.html"
    
            $params = @{'As'='Table';
                        'PreContent'='OS'}
    					
            $html_os = Get-InfoOS -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    	
         	$params	= @{'As'='List';
    					'PreContent'='Time Zone'
    					'Properties'= @{n='Time Zone';e={$_.TimeZone};css={if ($_.TimeZone -eq '(UTC) Co-ordinated Universal Time') { 'green' } else { 'red' }}}}
    		
    		$html_tz =  Get-TimeZone -ComputerName $computer |
    					ConvertTo-EnhancedHTMLFragment @params
    		
            $params = @{'As'='List';
                        'PreContent'='Computer System'}
    					
            $html_cs = Get-InfoCompSystem -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    			  
            $params = @{'As'='Table';
                        'PreContent'='Activation Status';
    					'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'TableCssClass'='grid';
    					'Properties'='ComputerName',
    							@{n='Status';e={$_.status};css={if ($_.status -eq 'Licensed') { 'green' } elseif ($_.status -eq 'Out-Of-Box Grace Period', 'Notification', 'Extended Grace', 'Out-Of-Tolerance Grace Period', 'Non-Genuine Grace Period') { 'yellow' } else { 'red' }}}}
    
            $html_as = Get-ActivationStatus -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    
            $params = @{'As'='Table';
                        'PreContent'='Local Disks';
                        'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'MakeTableDynamic'=$true;
                        'TableCssClass'='grid';
                        'Properties'='Drive',
                                     @{n='Size(GB)';e={$_.Size}},
                                     @{n='Free(GB)';e={$_.Free}},
                                     @{n='Free(%)';e={$_.FreePct};css={if ($_.FreePct -lt 10) { 'red' } elseif ($_.FreePct -lt 75) { 'yellow' } else { 'green' }}}}
    								 
            $html_dr = Get-InfoDisk -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params
    
            $params = @{'As'='Table';
                        'PreContent'='Services to CheckThe following services are set to Automatic Start but have not started';
                        'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'TableCssClass'='grid'}
    	        
    		$html_ft = Get-InstalledFeatures |
                       ConvertTo-EnhancedHTMLFragment @params 
    
            $params = @{'As'='list';
                        'PreContent'='Features Not Installed'}
    					
            $html_sv = Get-InfoBadService -ComputerName $computer |
                       ConvertTo-EnhancedHTMLFragment @params 
    
            $params = @{'As'='Table';
                        'PreContent'='NICs';
                        'EvenRowCssClass'='even';
                        'OddRowCssClass'='odd';
                        'TableCssClass'='grid'}
    					
            $html_na = Get-InfoNIC -ComputerName $Computer |
                       ConvertTo-EnhancedHTMLFragment @params
    
    
            $params = @{'CssStyleSheet'=$style;
                        'Title'="System Report for $computername";
                        'PreContent'="System Report for $computernameReport Generated by $UserName";
                        'HTMLFragments'=@($html_os,$html_tz,$html_cs,$html_as,$html_dr,$html_sv,$html_ft,$html_na)
                        } 
    					
            ConvertTo-EnhancedHTML @params |
            Out-File -FilePath $filepath
    		invoke-item -Path $filepath
    

    This is what i have and I cant get it to work. What I have done is create a text file with the features that should be isntalled and parse the currently installed features to a new text file and then do a compare-object on the two files. But it wont work. Can you help?

You must be logged in to reply to this topic.