Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
achimismaili opened this issue Sep 7, 2017 · 0 comments

Comments

@achimismaili
Copy link

achimismaili commented Sep 7, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant