how to get output from write-host into a file

Good afternoon experts, I’m attempting to capture hundreds of entries from the following section of code ( modified from a powershell gallery script) into a file. The Start and Stop transcript is not working for each write-host entry it starts and stops the transcript command. Was toying with the idea of using the $output currently commented with a for each loop but that did not work, the output was not what I was looking for – the content of write-host into a file. Wondering if anyone could help me out with this

Thank you

Norm

#This function is used to Catalog the orphaned SID 
   		$acl = Get-Acl -Path $Path
   		foreach($acc in $acl.access )
   		{
   			$value = $acc.IdentityReference.Value
   			if($value -match "S-1-5-*")
   			{
   				#Clear-Content -Path D:\PowerShell_temp\ListSIDFromACL_output.txt
                #Start Logging
                Start-Transcript -Path D:\Poweshell_temp\testlog0.txt
                Write-Host "List SID: $value  from  $Path"
                #Stop Logging 
                Stop-Transcript 
                #$Output = "List SID: $value  from  $Path"
                
   			}
   		}
  	}
   	catch
   	{
   		$errorlog = $Error | Out-String
        Clear-Content -Path D:\PowerShell_temp\ListSIDFromACL_errors.txt    
        Add-Content -Path D:\PowerShell_temp\ListSIDFromACL_errors.txt -Value $ErrorLog
   	}

You don’t. Okay, technically you can, but that’s not what Write-Host is for. As its name implies, it writes to the host interface, and nowhere else.

What you usually need for that is to store the value and then export it to the file. If storing that text and then exporting it isn’t getting you the data you’re after, then you might be seeing other output on the screen that isn’t from that particular command to start with. If I had to guess, I’d say it’s from the transcript commands.

 

Good afternoon,
In case anyone cares finally got it to work, note the following. I’m open to any and all corrections, if someone would have approached this differently please feel free to share.
Norm

#Clear Contents of Output file prior to Function
Clear-Content -Path D:\Powershell_temp\ListSIDFromACL_output.txt

Function CatalogSID([string]$path)
{  
  
  try
  	{
   		#This function is used to Catalog the orphaned SID 
   		$acl = Get-Acl -Path $Path
   		foreach($acc in $acl.access )
   		{
   			$value = $acc.IdentityReference.Value
   			if($value -match "S-1-5-*")
   			{
   				$Output = "List SID: $value  from  $Path"
                foreach($Outputs in $Output){$Outputs | Out-file D:\Powershell_temp\ListSIDFromACL_output.txt -Append}</strong
                                
   			}
   		}
  	}
   	catch
   	{
   		$errorlog = $Error | Out-String
        Clear-Content -Path D:\PowerShell_temp\ListSIDFromACL_errors.txt    
        Add-Content -Path D:\PowerShell_temp\ListSIDFromACL_errors.txt -Value $ErrorLog
   	}	
}

write-host foo 6>file.txt

or write-output instead