17

See for example this question related to PowerShell: https://stackoverflow.com/questions/28311739/powershell-getting-the-string-value-of-variable-manipulating-variable

Actual

And this is how I see it in PowerShell ISE:

Enter image description here

So I guess I'm saying... some color formatting would be nice :)

1

1 Answer 1

22

You can actually get syntax coloring for PowerShell if you add this line before your code:

<!-- language-all: lang-powershell -->

Demo:

$include = @("*.csv", "*.txt","*.dat")
$oldday = (Get-Date).AddDays(-2)
$path = "C:\TESTING\tester\test1\testfiles"

$Allfiles = Get-Childitem -Path $path -include $include -recurse| Where {!$_.PSIsContainer -and ($_.CreationTime -gt $oldday)} | Select-Object Fullname

foreach ($file in $Allfiles)
    {
       $file1 = $file.Fullname
       $foldername = Get-ChildItem -Path $file.Fullname
       $input = $foldername.Directoryname
       $Mothername = Get-Item -Path $input
       $output = $Mothername.Parent.Fullname
       $output = "$output\sc"
       Write-Host "The Filename: $file1"
       Write-Host "The FolderName: $input"
       Write-Host "$output"
       $argument = "$input $output $input"
    }

For more information, see What is syntax highlighting and how does it work?.

9
  • 1
    Why isn't this done automatically? This would force me to edit the questions to make them readable... Commented Feb 4, 2015 at 1:15
  • 1
    Well, the [powershell] tag isn't very popular (just 22,000 questions compared to the hundreds of thousands in tags like [java] or [c#]). SO simply hasn't added support for it to be automatically enabled yet.
    – user2555451
    Commented Feb 4, 2015 at 1:18
  • 1
    @HovercraftFullOfEels what a ridiculous argument... all I'm saying is, if the other languages have automatic coloring, why doesn't PowerShell? Commented Feb 4, 2015 at 1:24
  • 1
    @I19: Because no mod has stumbled over the need yet, nor been asked for it. Your question now will probably get one to take action. Commented Feb 4, 2015 at 2:33
  • Perhaps worth noting is use of <!-- language: lang-none --> after the code block in question, e.g. if some output or error message is formatted with four leading spaces. Commented Apr 9, 2017 at 9:44
  • All this is doing is making things that are capitalized in blue and quotes are in red. It only highlights "get" if it was small letters. It's better in github, with ```powershell at the start of the code, (which doesn't work here).
    – js2010
    Commented Aug 18, 2019 at 14:35
  • Powershell syntax highlighting in Stackoverflow is terrible.
    – js2010
    Commented Sep 16, 2019 at 1:55
  • The syntax highlighting in the demo doesn't look right for me
    – stevec
    Commented Feb 19, 2021 at 17:42
  • I would just use: 3 backticks as usual like ```lang-powershell \n\n ``` ... instead of the html comment
    – BananaAcid
    Commented Sep 25, 2022 at 23:05

Not the answer you're looking for? Browse other questions tagged .