none
PowerShell Colorization RRS feed

  • Question

  • This is not new, but this example demonstrates the problem with PowerShell colorization. Clearly, the backtick character is handled wrong:

    import-module activedirectory 
    $inputFile = Import-CSV  C:\test.csv
    foreach($line in $inputFile){ 
        New-ADUser `
            -SamAccountName $line.UserName `
            -name $line.FullName `
            -AccountPassword (ConvertTo-SecureString `
            -AsPlainText "Password" `
            -Force `
            -Enabled $true `
            -Path $line.ou `
            -DisplayName $line.FullName `
            -GivenName $line.FirstName `
            -Surname $line.SurName `
            -UserPrincipalName $line.UserPrincipalName `
            -PassThru
        $groups=$line.groups.Split('|')
        foreach($group in $groups){
            Add-ADGroupMember -Identity $group -Member $line.UserName
        }
    }


    Richard Mueller - MVP Directory Services

    Tuesday, February 14, 2012 6:06 PM
    Moderator

Answers

  • The colorization is a topic of a few bugs, powershell is one of them. I need to work out how to update the colorizer, since it isn't code we own. As far as the colorizing state, it's proabably related to how the client script is interruped by the forums ajax code while executing, that's my guess anyway.

    Community Forums Program Manager

    Thursday, February 16, 2012 6:21 AM
    Answerer

All replies

  • Brent, is this on the back log and written up?

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Experience Program Manager (Blog, Twitter, Wiki)

    Wednesday, February 15, 2012 6:31 PM
    Owner
  • Interesting observation - as soon as I mark reply as helpful or mark as answer or propose an answer - the colorization of the PowerShell script changes to all black. I noticed this the second time. Although now it's back to colored. Weird...

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    Thursday, February 16, 2012 4:06 AM
    Moderator
  • The colorization is a topic of a few bugs, powershell is one of them. I need to work out how to update the colorizer, since it isn't code we own. As far as the colorizing state, it's proabably related to how the client script is interruped by the forums ajax code while executing, that's my guess anyway.

    Community Forums Program Manager

    Thursday, February 16, 2012 6:21 AM
    Answerer
  • Is there a way to view the source of the "prettyprint" class?  I noticed the font isn't monospaced either in the end.

    • Edited by JS2010 Monday, January 1, 2018 8:42 PM
    Monday, January 1, 2018 8:40 PM
  • We have never seen the source for the prettyprint class. It is not Microsoft code. And I complained years ago that the code block feature in the forums uses a proportional font, which I feel is inappropriate for code.

    For years I used scripts to convert code and scripts into HTML that I could past into the HTML editor of a reply. The resulting HTML specified Courier New, a fixed width font, colorized the code, and included the <pre> tag so the reply would be recognized as "with code". I stopped using my scripts because the colorization rules changed, and sometimes a forum update caused my font specification to be ignored. But if you are interested, the scripts are on my web site linked here:

    http://www.rlmueller.net/ConvertCodeToHTML.htm


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Monday, January 1, 2018 9:04 PM
    Moderator
  • Sometimes I try to copy and paste from Vscode and put a <pre> tag at the top, but I have to reindent it and add blank lines (control-enter).  Vscode doesn't color powershell parameters (minor flaw), but it has multiple color themes.  It's sad that this state of the forum has been going on for years.  This is the default dark theme.  You can also copy and paste from ISE to Word to here, to some effect.  The powershell forum is also strangely narrow, but not this one.

    # This is a PowerShell comment.

    function
    MyFunction([Parameter(Position = 0)][System.String]$path)
    {
    :loopLabel foreach ($thisFile in (Get-ChildItem $path))
    {
    Write-Host ; Write-Host -Fore Yellow `
    ('Length: ') +
    [System.Math]::Floor($thisFile.Length / 1000)
    }
    }







    • Edited by JS2010 Tuesday, January 2, 2018 7:32 PM
    Monday, January 1, 2018 9:28 PM