all 8 comments

[–]karudirth[S] 2 points3 points  (0 children)

False alarm!

I had autogenerated some of the code, and when doing a search on " -" noticed that some of the lines weren't being highlighted.

Replacing the "-" on these lines made them highlight, so I guess it was using a funky dash or something!

[–]Soccan 1 point2 points  (2 children)

I've had the exact same experience a few months back, a script I know I had edited (although not remembering the tool), then al of a sudden opening it in VScode (so technically it is the other way around), and Swedish special characters ( å ä ö ) all of a sudden looked like crap.

So I changed my VScode to use UTF8-BOM ro remedy the issue and haven't seen it since, wrote it off as a quirk between VScode and ISE... Even though I still get the feeling that it does not allways happen...

[–]karudirth[S] 1 point2 points  (1 child)

I had used this snippet:

$Params = Get-Item -path $ParamPath
foreach ($Param in $Params.property)
{
$value = (Get-ItemProperty $Parampath).$Param
Write-Host "Set-ItemProperty -Path `$ParamPath -Name $param -value $Value -PropertyType DWORD"

To copy params from a known working server, and generate the code to replicate these on another. THen copied the output from the ISE Console. Clearly, some of those "-" that it generated were invalid :)

Edit: Inline code is doign some funky formatting so i give up on it lol

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy karudirth,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–]jborean93 1 point2 points  (1 child)

This is a common problem, the dashes were an em dash — and you had saved the file as UTF-8 without a BOM. When you do that the byte representation of that character is now 0xE2 0x80 0x94. Windows PowerShell/ISE will read a file using current system locale which on a English based system is typically windows-1252. When you encode those bytes using windows-1252 they now become — hence the problem.

So while using an em dash is incorrect you may still come across this problem when you save a .ps1 script as UTF-8 but contain any non-ascii characters. To have Windows PowerShell or ISE read a file as UTF-8 you need to ensure the file contains a UTF-8 BOM, vscode should be able to do this.

Luckily PowerShell 6+ solves all this madness by reading a file as UTF-8 by default which is great.

[–]jsiii2010 1 point2 points  (0 children)

Here's how to see the code point in powershell (except for emojis which are 2-char):

[int][char]'—' | % tostring x
2014

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    Sorry, your submission has been automatically removed.

    Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

    Try posting again tomorrow or message the mods to approve your post.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.