Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1808634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:17:09+00:00 2026-05-17T06:17:09+00:00

With powershell 2.0: write-output abcd >> mytext.txt returns: a nul b nul c nul

  • 0

With powershell 2.0:

write-output "abcd" >> mytext.txt  

returns:

a nul b nul c nul d nul

od -c shows the nul as a true binary zero, \0 , or: a \0 b \0 c \0 d \0 (and \r \0 \n \0).

I am trying to generate some SQL, so I don’t think this will do. Any ideas of what’s going on and how to use write-output to just get the specified characters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:17:10+00:00Added an answer on May 17, 2026 at 6:17 am

    This is because write-output defaults to UTF-16 text encoding, which is 2 bytes per character. When you are dealing with text that fits into the ASCII codepage range, the 2nd byte of each character will be zero.

    This is controlled by the $OutputEncoding global variable, so you could set that to ASCII.

    Another option is to use the cmdlet Out-File, which has an explicit encoding parameter. I would suggest you use this instead of output redirection, because that saves you from changing your environment globally (by setting the global preference variable $OutputEncoding)

    Using Out-File, and setting encoding to be ASCII, your example would look like this:

    "abcd" | out-file "mytext.txt" -Encoding ASCII
    

    Do be aware that not all characters are representable in ASCII, and you should determine whether this is an appropiate encoding for your purpose. Personally I would typically go for UTF-8, since it is ASCII equivalent when characters fall in the ASCII range from 0-127, but also handles international characters. Obligatory link about text encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some PowerShell functions that do some stuff and then transparently
I have a powershell script that gives some status output via write-output . I
I'm trying to write a powershell script that updats each of the DiagnosticsConnectionString and
I trying to write a PowerShell script (learning at the same time). I have
I'm trying to write a custom powershell script that will create a local user
I have a PowerShell script: param ( [Parameter(Mandatory=$true)][string]$input, [Parameter(Mandatory=$true)][string]$table ) Write-Host Args: $Args.Length Get-Content
Consider the following PowerShell script: function Alpha { # write-output 'Uncomment this line and
I'm trying to change the color of write-host output based on the lastrunoutcome property
I am trying to loop through some controls in a Powershell / WPF application.
I'm trying to write a PowerShell script that will do the following: Executes a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.