PowerShell 2 Start-Transcript question

OK, I know PS2 is obsolete, however, I have no choice, so no flames please.

I have configured a task to run a PowerShell Script which does extensive logging via Start-Transcript. What I have noticed is that each line of the log file is truncated to 80 characters. Not the end of the world, but I am looking for a way/setting to have it honor the string length sent to the log file.

If I run the script from a command shell, it honors the Width setting of the shell under properties. That seems to be where the 80 char line limit is coming from. I tried changing the setting for the user running the script, but the task still truncates at 80 chars.

I also did not see any options to Start-Transcript that would be relevant. Again, not the end of the world, it just makes for an ugly log file. If there is a way around this, I would greatly appreciate the setting that will help.

What do you get if you run mode in the PowerShell console? Use the same user account that runs the task.

PS C:\> mode                                                                                                   
Status for device COM4:
-----------------------
    Baud:            1200
    Parity:          None
    Data Bits:       7
    Stop Bits:       1
    Timeout:         OFF
    XON/XOFF:        OFF
    CTS handshaking: OFF
    DSR handshaking: OFF
    DSR sensitivity: OFF
    DTR circuit:     ON
    RTS circuit:     ON


Status for device CON:
----------------------
    Lines:          3000
    Columns:        111
    Keyboard rate:  31
    Keyboard delay: 1
    Code page:      437

I get:

Status for device CON:

Lines: 3000
Columns: 120
Keyboard rate: 31
Code page: 437

Keep in mind, we are talking XP here. Note that Columns is exactly what I set it to via the command properties, however, that is not being honored when run from a scheduled task as that user. Ooops … I just noticed I left that part out of my original post. Sorry about that, I thought it was there. All is good except when run from the task.

I assume when the task runs, it should use whatever is configured for the console host but I am not sure.

What happens if you add “mode 1000” at the beginning of the script that is executed by the scheduled task? This would increase the number of columns from 120 to 1000 during the task execution. I can’t assure you that it works but it’s worth a try.

Increasing the Buffer Size (Width) worked for me even after running the script from Task Scheduler.

$host = Get-Host
$window = $host.ui.rawui
$newsize = $window.buffersize
$newsize.height = 3000
$newsize.width = 300 #specify the new width
$window.buffersize = $newsize
Start-Transcript -Path "C:\Users\james\Downloads\Documents\transcript.txt" -Force
write "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Stop-Transcript

James, that worked perfectly. Thank you very much :slight_smile:

Not sure if my last reply got through, things are a tad wonky.

James, that worked perfectly. Thank you very much :slight_smile:

Mode seems to do the same. I ran this on a maximized PowerShell console window.

PS C:\> $Host.UI.RawUI.BufferSize

Width Height
----- ------
  197   3000

PS C:\> mode 250
PS C:\> $Host.UI.RawUI.BufferSize

Width Height
----- ------
  250   3000

 

Good to know. Thank you.