locked
Notepad++ vs PowerShell ISE RRS feed

  • Question

  • I recently started using PowerShell and I've found that using Notepad++ can mangle a script yet display the correct visual. If I open the same code in PowerShell ISE I can easily spot the problem. Am I missing an update or an addin or something else that will keep my scripts clean? What are the preferred programs for writing/editing PowerShell scripts? 

    Thanks, 

    Joe B 

    Wednesday, April 1, 2020 11:43 PM

All replies

  • Visual Studio Code including the Powershell extension.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Thursday, April 2, 2020 12:55 AM
  • You need to set the correct file encoding in notepad++.  This is always because encoding and newline is set incorrectly in notepad++

    \_(ツ)_/

    Thursday, April 2, 2020 3:18 AM
  • Notepad++ works fine for me, even on unix text.  I'm not sure what anyone means.
    Thursday, April 2, 2020 4:00 AM
  • Notepad++ works fine for me, even on unix text.  I'm not sure what anyone means.

    If the default line terminator sequence is set to Unix it won't dis0play nicely in many Windows programs.  Unix uses a single LF (0x10) character and Windows uses a CrLf pair (0x13 0x10) to terminate a line.

    Also the default encoding in older versions of NP++ was set for Unix and can be an issue with some Windows console displays.

    VSCode is a much better editor for PowerShell than either ISE of NP++.


    \_(ツ)_/

    Thursday, April 2, 2020 11:17 AM
  • Thanks jrv. I will find, download, install, and start using VSCode. I'll let you know my first impressions.  

    Thanks again, 

    Joe B 

    Thursday, April 2, 2020 4:06 PM
  • You can also just set the NP++ encoding and line terminator.  I use more than one editor since each has capabilities that the others may not have.


    \_(ツ)_/

    Thursday, April 2, 2020 4:16 PM
  • The only program I've seen have a problem with unix text is the original Notepad.  Although strangely it can open bom-less utf16, which can happen in windows.
    Thursday, April 2, 2020 5:25 PM
  • BOM-LESS UTF -16?  Where di you find that?  Any byte stream opened that doesn't have a BOM is opened as UTF-8.  Originally Windows opened all untagged streams as ASCII which is sort of a subset of UTF-8 but the character set in place may disrupt the resulting display.

    File encoding has nothing to do with character encoding.  You have to forgive this unfortunate wacky use of the word "encoding".  A file is encoded with a BOM.  The BOM determines which Unicode encoding i in use.  It is almost impossible that a file would have something that looks like a BOM and not be Unicode.  Originally files were just byte streams and the byes were interpreted by the OS.  Unix and Windows as well as other systems had two big issues, byte order and line terminator.  Unicode was developed to allow all systems to share files and know how the file was assembled.  Of course this only works well if all files have a BOM. 

    Currently Windows defaults to UTF-8 with nio BOM which is the Unicode standard.  Adding a BOM can have weird issues due to translation when files are moved between system or when the files have been converted to a different Unicode encoding.  There are numerous articles that explain the issues.

    Start by carefully reviewing the Wikipedia article as it is a good baseline for understanding Unicode and how it works.

    Notepad++ usually just has the encoding and line terminator set wrong.  The latest versions are set correctly for almost systems but upgrading will not reset the earlier poor settings.

    Also instructions form well meaning but misinformed users may cause a user to set NP++ incorrectly although it may appear to work when not using PowerShell or other full Unicode application.  One day I may try to collect all of the th9ings that can cause issues.

    If you are having issues with NP++ files and PowerShell then the best place to get the most current help is in an NP++ forum.


    \_(ツ)_/

    Thursday, April 2, 2020 5:41 PM
  • Here's an example of windows making a utf16 ("unicode") no bom file:


    icacls . /save file.txt


    Notepad is magically able to display it correctly  In the ISE, it just looks binary.  Oh, it actually looks ok in notepad++ or vscode, nice.  There's other files like this in windows; sometimes text files output by different programs.

    • Edited by JS2010 Friday, April 3, 2020 1:51 PM
    Friday, April 3, 2020 1:46 PM
  • Ok yes.  NP does detect the nulls and assumes it is Unicode.  This is not a legitimate thing and should not be relied on.

    I never tried that with NP as no systems should produce a file like that.  


    \_(ツ)_/

    Friday, April 3, 2020 2:47 PM
  • OH!!! Notepad!!! I have from time to time done edits on my scripts using Notepad. I should have known better because I've been told before that Notepad can put inaccurately translated characters in a file. Now I'm not so sure my problem was with NotePad++. I've downloaded VSCode but haven't used it yet. 

    Thanks, 

    Joe B 

    Friday, April 3, 2020 10:49 PM
  • OH!!! Notepad!!! I have from time to time done edits on my scripts using Notepad. I should have known better because I've been told before that Notepad can put inaccurately translated characters in a file. Now I'm not so sure my problem was with NotePad++. I've downloaded VSCode but haven't used it yet. 

    Thanks, 

    Joe B 

    Notepad never puts characters in a file.  Only the user typing into notepad can put in characters.  What you are saying is that notepad can create a file that cannot be read by some older programs if notepad saves the file in the wrong encoding.  This has nothing to do with notepad or Windows but is about how much computer science a user knows.


    \_(ツ)_/

    Friday, April 3, 2020 10:57 PM
  • Ahhhhh... That makes much more sense. 

    Thanks jrv, 

    Joe B 

    Friday, April 3, 2020 11:03 PM
  • The gpo log file c:\windows\debug\usermode\gpsvc.log is also unicode (utf16-le) no bom.

    • Edited by JS2010 Friday, April 17, 2020 7:10 PM
    Friday, April 17, 2020 5:14 AM
  • In current Windows all notepad files are UTF-8 NOBOM which is the Unicode recommendation.

    See the Unicode specs for UTF-8 to understand why.

    Read the following very carefully: https://en.wikipedia.org/wiki/UTF-8


    \_(ツ)_/

    Friday, April 17, 2020 7:59 AM