Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Write-Host Seems to Truncate Strings.

$
0
0

Here is what I am running, but it seems write-host truncates the $error variable when passed to it. Output is below the code.

How can I get the error into a string and output to log file?

$ErrorView='NormalView'
$error.Clear()
$body = ''
$body1 = ''

try {

Get-Item afilethatdoesntexist.txt -ErrorAction Stop

  } catch {

  $error
  "
 
  ~~~~~~~~~~~~~~~~~~~  BREAK  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
  "
  Write-Host $error
  Exit 999
 }

Get-Item : Cannot find path 'C:\Windows\System32\WindowsPowerShell\v1.0\afilethatdoesntexist.txt' because it does not exist.
At X:\prea\Jobs\Untitled3.ps1:11 char:1
+ Get-Item afilethatdoesntexist.txt -ErrorAction Stop
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Windows\Syst...doesntexist.txt:String) [Get-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
 

 
  ~~~~~~~~~~~~~~~~~~~  BREAK  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
Cannot find path 'C:\Windows\System32\WindowsPowerShell\v1.0\afilethatdoesntexist.txt' because it does not exist.

Thank you!!    --Goo


Viewing all articles
Browse latest Browse all 8411

Trending Articles