Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

add colour to powershell script

Hi Guys,

How do I add colour to the result on the script below, example the running to be font colour green, the ones not running background red, etc.

$inputFiles = ".\londoncomps1.csv", ".\RomaniaComps.csv", ".\Singaporecomps.csv", ".\usacomps.csv"
$outputFile = "FireEyeServices_1.csv"
$inputFiles | ForEach `
{
    $file = $_

    import-csv $file | ForEach `
    {
        $Server = $_ | select -ExpandProperty hostname
	$Username = $_ | select -ExpandProperty username
        if ( Test-Connection -ComputerName $Server -Count 2 -Quiet )
        {
            Try
            {
                If ( $services = Get-Service *xagt* -ComputerName $Server )
                {
                    $services | Select Status, DisplayName, machinename, @{n="Username";e={$Username}},
                                @{n="SourceFile";e={$file}}
                }
                Else
                {
                    "" | Select @{n="Status";e={"Services not found"}},
                                @{n="DisplayName";e={"FireEye Services"}},
                                @{n="Machinename";e={$Server}},
				@{n="Username";e={$Username}},
                                @{n="SourceFile";e={$file}}
                }
		
      
            }
            Catch
            {
                "" | Select @{n="Status";e={"Error checking services"}},
                                @{n="DisplayName";e={""}},
                                @{n="Machinename";e={$Server}},
				@{n="Username";e={$Username}},
                                @{n="SourceFile";e={$file}}
            }
        }
        else 
        {
            "" | Select @{n="Status";e={"Couldn't ping server"}},
                        @{n="DisplayName";e={""}},
                        @{n="Machinename";e={$Server}},
						@{n="Username";e={$Username}},
                        @{n="SourceFile";e={$file}}
        }
    }
} | Export-Csv $outputFile -NoTypeInformation

Open in new window

Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

CSV files do not support colours, they're text only. You would have to write to Excel, and you would have to set the colours yourself. This is not built into PowerShell.

Alternatively, write as HTML?
Avatar of Kelly Garcia

ASKER

yea how do I write it as html or to excel?
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland 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