Powershell: How to change cell color based on text?

I have below script which gives list of local admin members.

I was wondering if you techies can help me, highlight the bold output to be in red background color cell in result excel file.

Function LocalAdmin


$GFile = New-Item -type file -force "C:\Scripts\SGroupMemberDetails.xls"

Import-Csv "C:\Scripts\Servers.csv" | ForEach-Object {

$SName = $_.ServerName

$AdminPath = Test-Path "\\$SName\admin$\"

If ($AdminPath -eq $TRUE)


Write-host -nonewline "Collecting Admin info from $SName...."

"Server Name - $SName" | Out-File $GFile -encoding ASCII -append

$group = [ADSI]("WinNT://$SName/Administrators,group")

$GMembers = $group.psbase.invoke("Members")

$GMembers | ForEach-Object {$_.GetType().InvokeMember("Name",'GetProperty', $null, $_, $null) | Out-File $GFile -encoding ASCII -append}

Write-host "......Done!"




write-host -fore Red "Cannot Acces $SName"

out-file -inputObject "Server - $SName -> ########Cannot Access" -filepath $GFile -encoding ASCII -append


$GMembers = ""






No Data
Reply Children
No Data