Skip to content

Log file not written correctly on Windows Server 2012 R2 with PowerShell 4 #22

@achimismaili

Description

@achimismaili

The logging is not working correctly in Windows Server 2012 R2 with PowerShell 4.
Every entry, that is internally created via the Log function is not logged in the file, only listed in the console.

The cause is a bug in windows server 2012 R2.
This issue is also discussed in Technet: https://social.technet.microsoft.com/Forums/windowsserver/en-US/cecc4f32-28c8-4bdc-be63-49ce3d396625/powershell-4-starttranscript-does-not-log-writehost?forum=winserverpowershell
There exists a hotfix for windows server: see https://support.microsoft.com/en-us/kb/3014136

Alternatively, you can replace Write-Host with Write-Out or Out-Host.
In SPSD_Utilities.ps1, the Write-Host is used 4 times.
It is not working to just replace Write-Host with Write-Output.
For Windows Server 2012 R2, you can just overwrite Write-Output with the following function, just inserted it below (Line 102)

            # region Utilities.Logging
	    # region Log 

This is the function to insert:

 # replacement for Write-Host, which does not work for specific constellations of PS4 and Win Server 2012 R2
		# see Hotfix https://support.microsoft.com/en-us/kb/3014136
		Function Write-Host ($message,[switch] $nonewline,$backgroundcolor,$foregroundcolor) {
			$Message | Out-Host
		 }

I don't think, this should be added to the standard SPSD functionality, therefore I did not change it as a Pull request. To create an issue seemed to be a good idea to me. Maybe s.o. finds an intelligent way to include this in the script, has a good place where to put this as a heads up or in the simplest case, maybe just adds this information as comment in the log function...?

Cheers,
Achim

Some further information in German related to the logging issue can also be found here:
https://www.msxfaq.de/code/powershell/writehostdebugging.htm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions