Results 1 to 8 of 8
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Defining a property in PowerShell

    I am trying something, I thought, simple: Change the colors of the PowerShell window.

    So I entered "this", and got back:

    PS: 06/28/2016 18:00:42> $a.WarningBackgroundColor = "red"
    The property 'WarningBackgroundColor' cannot be found on this object. Verify that the property exists and can
    be set.
    At line:1 char:1
    + $a.WarningBackgroundColor = "red"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: ( [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

    PS: 06/28/2016 18:00:57>

    So do I define properties (such as one for each color attribute I want to change) before I can implement the change?

    Say I want error messages to be bright white on red. I input

    $a.ErrorBackgroundColor = "red"
    $a.ErrorForegroundColor = "white"

    In profile.ps1, but got the above error. What am I doing wrong or missing?

    Chuck Billow
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,594
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    Did you read the article - Modifying Message Colors?

    Did you include the Get-Host cmdlet?
    Joe

  3. #3
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Although I could not access that page, Joe, I did find what I needed at

    http://powershell-tips.blogspot.com/...-location.html

    Chuck
    -------------------

    Kind of, Joe, and no. I'll go take a look.

    Oops... That page is no longer available.

    Thanks,
    Chuck
    Last edited by CWBillow; 2016-06-28 at 22:01.
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  4. #4
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,594
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    Try the link again. I updated it.
    Joe

  5. #5
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Joe, that one worked. Thanks.

    I have two scripts in C:\Users\CWBillow\Documents\WindowsPowerShell: Microsoft.PowerShell_profile and profile.

    Do these both run at startup? And does one or the other take precedence?

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  6. #6
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,594
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    I'm not sure. Could be one works with "run as admin" and the other with normal permissions. Put what you want in one and see if it works.
    Joe

  7. #7
    WS Lounge VIP Browni's Avatar
    Join Date
    Dec 2009
    Location
    Rochdale, UK
    Posts
    1,655
    Thanks
    38
    Thanked 161 Times in 139 Posts
    Google is your friend here! Linky

  8. The Following User Says Thank You to Browni For This Useful Post:

    CWBillow (2016-06-30)

  9. #8
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Browni, that sure helps.

    Thanks,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •