Windows Vista Forums

what just happened?
  1. #1


    Larry__Weiss Guest

    what just happened?

    I was playing around with ways to quickly turn on and off sections of my
    profile.ps1 and at one time ended up with this content (everything indented 4
    spaces)

    <# Larry's PowerShell profile #>
    <# #>
    # if (1)
    {
    # use black on white for all text
    # --------------------------------
    $Host.Ui.RawUi.BackGroundColor = "White"
    $Host.Ui.RawUi.ForeGroundColor = "Black"
    $host.privatedata.ErrorForegroundColor = "Black"
    $host.privatedata.ErrorBackgroundColor = "White"
    $host.privatedata.WarningForegroundColor = "Black"
    $host.privatedata.WarningBackgroundColor = "White"
    $host.privatedata.DebugForegroundColor = "Black"
    $host.privatedata.DebugBackgroundColor = "White"
    $host.privatedata.VerboseForegroundColor = "Black"
    $host.privatedata.VerboseBackgroundColor = "White"
    $host.privatedata.ProgressForegroundColor = "Black"
    $host.privatedata.ProgressBackgroundColor = "White"
    }
    # cls
    "WindowsPowerShell\profile.ps1"
    <# #>

    When it runs, I get this on the screen

    Windows PowerShell V2 (Community Technology Preview - Features Subject ...
    Copyright (C) 2008 Microsoft Corporation. All rights reserved.




    # use black on white for all text
    # --------------------------------
    $Host.Ui.RawUi.BackGroundColor = "White"
    $Host.Ui.RawUi.ForeGroundColor = "Black"
    $host.privatedata.ErrorForegroundColor = "Black"
    $host.privatedata.ErrorBackgroundColor = "White"
    $host.privatedata.WarningForegroundColor = "Black"
    $host.privatedata.WarningBackgroundColor = "White"
    $host.privatedata.DebugForegroundColor = "Black"
    $host.privatedata.DebugBackgroundColor = "White"
    $host.privatedata.VerboseForegroundColor = "Black"
    $host.privatedata.VerboseBackgroundColor = "White"
    $host.privatedata.ProgressForegroundColor = "Black"
    $host.privatedata.ProgressBackgroundColor = "White"

    WindowsPowerShell\profile.ps1
    PS C:\Documents and Settings\Larry>


    Why do I get that exact output? None of the statements that set color executed,
    but their source was echoed to the screen.

    - Larry

      My System SpecsSystem Spec

  2. #2


    Vadims Podans [MVP] Guest

    Re: what just happened?

    remove braces from this code. Or remove comment character from IF statement
    line. And if you want run this Profile.ps1 file - insert dot with slash to
    path:

    ..\WindowsPowerShell\profile.ps1
    (if WindowsPowerShell folder exist in %userprofile% folder).
    --
    WBR, Vadims Podans
    MVP: PowerShell
    PowerShell blog - www.sysadmins.lv

    "Larry__Weiss" <lfw@xxxxxx> rakstija zinojuma
    "news:eTJ6lRLCKHA.1380@xxxxxx"...

    > I was playing around with ways to quickly turn on and off sections of my
    > profile.ps1 and at one time ended up with this content (everything
    > indented 4 spaces)
    >
    > <# Larry's PowerShell profile #>
    > <# #>
    > # if (1)
    > {
    > # use black on white for all text
    > # --------------------------------
    > $Host.Ui.RawUi.BackGroundColor = "White"
    > $Host.Ui.RawUi.ForeGroundColor = "Black"
    > $host.privatedata.ErrorForegroundColor = "Black"
    > $host.privatedata.ErrorBackgroundColor = "White"
    > $host.privatedata.WarningForegroundColor = "Black"
    > $host.privatedata.WarningBackgroundColor = "White"
    > $host.privatedata.DebugForegroundColor = "Black"
    > $host.privatedata.DebugBackgroundColor = "White"
    > $host.privatedata.VerboseForegroundColor = "Black"
    > $host.privatedata.VerboseBackgroundColor = "White"
    > $host.privatedata.ProgressForegroundColor = "Black"
    > $host.privatedata.ProgressBackgroundColor = "White"
    > }
    > # cls
    > "WindowsPowerShell\profile.ps1"
    > <# #>
    >
    > When it runs, I get this on the screen
    >
    > Windows PowerShell V2 (Community Technology Preview - Features Subject
    > ...
    > Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >
    >
    > # use black on white for all text
    > # --------------------------------
    > $Host.Ui.RawUi.BackGroundColor = "White"
    > $Host.Ui.RawUi.ForeGroundColor = "Black"
    > $host.privatedata.ErrorForegroundColor = "Black"
    > $host.privatedata.ErrorBackgroundColor = "White"
    > $host.privatedata.WarningForegroundColor = "Black"
    > $host.privatedata.WarningBackgroundColor = "White"
    > $host.privatedata.DebugForegroundColor = "Black"
    > $host.privatedata.DebugBackgroundColor = "White"
    > $host.privatedata.VerboseForegroundColor = "Black"
    > $host.privatedata.VerboseBackgroundColor = "White"
    > $host.privatedata.ProgressForegroundColor = "Black"
    > $host.privatedata.ProgressBackgroundColor = "White"
    >
    > WindowsPowerShell\profile.ps1
    > PS C:\Documents and Settings\Larry>
    >
    >
    > Why do I get that exact output? None of the statements that set color
    > executed, but their source was echoed to the screen.
    >
    > - Larry

      My System SpecsSystem Spec

  3. #3


    tojo2000 Guest

    Re: what just happened?

    On Jul 19, 2:03*pm, Larry__Weiss <l...@xxxxxx> wrote:

    > I was playing around with ways to quickly turn on and off sections of my
    > profile.ps1 and at one time ended up with this content (everything indented 4
    > spaces)
    >
    > * * <# Larry's PowerShell profile #>
    > * * <# #>
    > * * # if (1)
    > * * {
    > * * * * # use black on white for all text
    > * * * * # --------------------------------
    > * * * * $Host.Ui.RawUi.BackGroundColor = "White"
    > * * * * $Host.Ui.RawUi.ForeGroundColor = "Black"
    > * * * * $host.privatedata.ErrorForegroundColor * *= "Black"
    > * * * * $host.privatedata.ErrorBackgroundColor * *= "White"
    > * * * * $host.privatedata.WarningForegroundColor *= "Black"
    > * * * * $host.privatedata.WarningBackgroundColor *= "White"
    > * * * * $host.privatedata.DebugForegroundColor * *= "Black"
    > * * * * $host.privatedata.DebugBackgroundColor * *= "White"
    > * * * * $host.privatedata.VerboseForegroundColor *= "Black"
    > * * * * $host.privatedata.VerboseBackgroundColor *= "White"
    > * * * * $host.privatedata.ProgressForegroundColor = "Black"
    > * * * * $host.privatedata.ProgressBackgroundColor = "White"
    > * * }
    > * * # cls
    > * * "WindowsPowerShell\profile.ps1"
    > * * <# #>
    >
    > When it runs, I get this on the screen
    >
    > * * *Windows PowerShell V2 (Community Technology Preview - FeaturesSubject ...
    > * * *Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >
    > * * * * *# use black on white for all text
    > * * * * *# --------------------------------
    > * * * * *$Host.Ui.RawUi.BackGroundColor = "White"
    > * * * * *$Host.Ui.RawUi.ForeGroundColor = "Black"
    > * * * * *$host.privatedata.ErrorForegroundColor * *= "Black"
    > * * * * *$host.privatedata.ErrorBackgroundColor * *= "White"
    > * * * * *$host.privatedata.WarningForegroundColor *= "Black"
    > * * * * *$host.privatedata.WarningBackgroundColor *= "White"
    > * * * * *$host.privatedata.DebugForegroundColor * *= "Black"
    > * * * * *$host.privatedata.DebugBackgroundColor * *= "White"
    > * * * * *$host.privatedata.VerboseForegroundColor *= "Black"
    > * * * * *$host.privatedata.VerboseBackgroundColor *= "White"
    > * * * * *$host.privatedata.ProgressForegroundColor = "Black"
    > * * * * *$host.privatedata.ProgressBackgroundColor = "White"
    >
    > * * *WindowsPowerShell\profile.ps1
    > * * *PS C:\Documents and Settings\Larry>
    >
    > Why do I get that exact output? *None of the statements that set color executed,
    > but their source was echoed to the screen.
    >
    > * - Larry
    The reason why it's just printed out is because all you did was create
    an anonymous script block. The if statement executes a scriptblock,
    but you didn't tell PowerShell to do anything with the scriptblock, so
    it just output the contents as the default output for that object type.

      My System SpecsSystem Spec

  4. #4


    Larry__Weiss Guest

    Re: what just happened?

    tojo2000 wrote:

    > On Jul 19, 2:03 pm, Larry__Weiss <l...@xxxxxx> wrote:

    >> I was playing around with ways to quickly turn on and off sections of my
    >> profile.ps1 and at one time ended up with this content (everything indented 4
    >> spaces)
    >>
    >> <# Larry's PowerShell profile #>
    >> <# #>
    >> # if (1)
    >> {
    >> # use black on white for all text
    >> # --------------------------------
    >> $Host.Ui.RawUi.BackGroundColor = "White"
    >> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >> $host.privatedata.ErrorForegroundColor = "Black"
    >> $host.privatedata.ErrorBackgroundColor = "White"
    >> $host.privatedata.WarningForegroundColor = "Black"
    >> $host.privatedata.WarningBackgroundColor = "White"
    >> $host.privatedata.DebugForegroundColor = "Black"
    >> $host.privatedata.DebugBackgroundColor = "White"
    >> $host.privatedata.VerboseForegroundColor = "Black"
    >> $host.privatedata.VerboseBackgroundColor = "White"
    >> $host.privatedata.ProgressForegroundColor = "Black"
    >> $host.privatedata.ProgressBackgroundColor = "White"
    >> }
    >> # cls
    >> "WindowsPowerShell\profile.ps1"
    >> <# #>
    >>
    >> When it runs, I get this on the screen
    >>
    >> Windows PowerShell V2 (Community Technology Preview - Features Subject ...
    >> Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >>
    >> # use black on white for all text
    >> # --------------------------------
    >> $Host.Ui.RawUi.BackGroundColor = "White"
    >> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >> $host.privatedata.ErrorForegroundColor = "Black"
    >> $host.privatedata.ErrorBackgroundColor = "White"
    >> $host.privatedata.WarningForegroundColor = "Black"
    >> $host.privatedata.WarningBackgroundColor = "White"
    >> $host.privatedata.DebugForegroundColor = "Black"
    >> $host.privatedata.DebugBackgroundColor = "White"
    >> $host.privatedata.VerboseForegroundColor = "Black"
    >> $host.privatedata.VerboseBackgroundColor = "White"
    >> $host.privatedata.ProgressForegroundColor = "Black"
    >> $host.privatedata.ProgressBackgroundColor = "White"
    >>
    >> WindowsPowerShell\profile.ps1
    >> PS C:\Documents and Settings\Larry>
    >>
    >> Why do I get that exact output? None of the statements that set color executed,
    >> but their source was echoed to the screen.
    >>
    >
    > The reason why it's just printed out is because all you did was create
    > an anonymous script block. The if statement executes a scriptblock,
    > but you didn't tell PowerShell to do anything with the scriptblock, so
    > it just output the contents as the default output for that object type.
    >
    In my case the if statement was commented out.
    I did not get the side-effects of the color settings.
    But I did get the source pf the script block written to the screen.

    - Larry


      My System SpecsSystem Spec

  5. #5


    Joel Bennett Guest

    Re: what just happened?

    If you write a scriptblock like { write-host "Hello World" } ... it is
    an object. PowerShell is, essentially, a functional language in this
    respect: the ScriptBlock/Function is a first-class object. By default,
    it's .ToString() is the contents, which is what you're seeing.

    If you want it to be EXECUTED instead of output to the pipeline as an
    object, you need the CALL operator: &{ Write-Host "Hello World" } ...
    (or you can just uncomment the IF($true) that you've got there ;-)
    --
    Joel

    Larry__Weiss wrote:

    > tojo2000 wrote:

    >> On Jul 19, 2:03 pm, Larry__Weiss <l...@xxxxxx> wrote:

    >>> I was playing around with ways to quickly turn on and off sections of my
    >>> profile.ps1 and at one time ended up with this content (everything
    >>> indented 4
    >>> spaces)
    >>>
    >>> <# Larry's PowerShell profile #>
    >>> <# #>
    >>> # if (1)
    >>> {
    >>> # use black on white for all text
    >>> # --------------------------------
    >>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>> $host.privatedata.ErrorForegroundColor = "Black"
    >>> $host.privatedata.ErrorBackgroundColor = "White"
    >>> $host.privatedata.WarningForegroundColor = "Black"
    >>> $host.privatedata.WarningBackgroundColor = "White"
    >>> $host.privatedata.DebugForegroundColor = "Black"
    >>> $host.privatedata.DebugBackgroundColor = "White"
    >>> $host.privatedata.VerboseForegroundColor = "Black"
    >>> $host.privatedata.VerboseBackgroundColor = "White"
    >>> $host.privatedata.ProgressForegroundColor = "Black"
    >>> $host.privatedata.ProgressBackgroundColor = "White"
    >>> }
    >>> # cls
    >>> "WindowsPowerShell\profile.ps1"
    >>> <# #>
    >>>
    >>> When it runs, I get this on the screen
    >>>
    >>> Windows PowerShell V2 (Community Technology Preview - Features
    >>> Subject ...
    >>> Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >>>
    >>> # use black on white for all text
    >>> # --------------------------------
    >>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>> $host.privatedata.ErrorForegroundColor = "Black"
    >>> $host.privatedata.ErrorBackgroundColor = "White"
    >>> $host.privatedata.WarningForegroundColor = "Black"
    >>> $host.privatedata.WarningBackgroundColor = "White"
    >>> $host.privatedata.DebugForegroundColor = "Black"
    >>> $host.privatedata.DebugBackgroundColor = "White"
    >>> $host.privatedata.VerboseForegroundColor = "Black"
    >>> $host.privatedata.VerboseBackgroundColor = "White"
    >>> $host.privatedata.ProgressForegroundColor = "Black"
    >>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>
    >>> WindowsPowerShell\profile.ps1
    >>> PS C:\Documents and Settings\Larry>
    >>>
    >>> Why do I get that exact output? None of the statements that set color
    >>> executed,
    >>> but their source was echoed to the screen.
    >>>
    >>
    >> The reason why it's just printed out is because all you did was create
    >> an anonymous script block. The if statement executes a scriptblock,
    >> but you didn't tell PowerShell to do anything with the scriptblock, so
    >> it just output the contents as the default output for that object type.
    > >
    >
    > In my case the if statement was commented out.
    > I did not get the side-effects of the color settings.
    > But I did get the source pf the script block written to the screen.
    >
    > - Larry
    >

      My System SpecsSystem Spec

  6. #6


    Larry__Weiss Guest

    Re: what just happened?

    It was just an accident in refactoring that code that produced it, nothing
    intentional. Nevertheless, I wanted to understand it.
    Thanks for the explanation.

    I went further and played with constructions like
    { 0/0 }
    I don't understand why that expression throws an error if it is not actually
    executed.

    - Larry



    Joel Bennett wrote:

    > If you write a scriptblock like { write-host "Hello World" } ... it is
    > an object. PowerShell is, essentially, a functional language in this
    > respect: the ScriptBlock/Function is a first-class object. By default,
    > it's .ToString() is the contents, which is what you're seeing.
    >
    > If you want it to be EXECUTED instead of output to the pipeline as an
    > object, you need the CALL operator: &{ Write-Host "Hello World" } ...
    > (or you can just uncomment the IF($true) that you've got there ;-)
    > --
    > Joel
    >
    > Larry__Weiss wrote:

    >> tojo2000 wrote:

    >>> On Jul 19, 2:03 pm, Larry__Weiss <l...@xxxxxx> wrote:
    >>>> I was playing around with ways to quickly turn on and off sections
    >>>> of my
    >>>> profile.ps1 and at one time ended up with this content (everything
    >>>> indented 4
    >>>> spaces)
    >>>>
    >>>> <# Larry's PowerShell profile #>
    >>>> <# #>
    >>>> # if (1)
    >>>> {
    >>>> # use black on white for all text
    >>>> # --------------------------------
    >>>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>>> $host.privatedata.ErrorForegroundColor = "Black"
    >>>> $host.privatedata.ErrorBackgroundColor = "White"
    >>>> $host.privatedata.WarningForegroundColor = "Black"
    >>>> $host.privatedata.WarningBackgroundColor = "White"
    >>>> $host.privatedata.DebugForegroundColor = "Black"
    >>>> $host.privatedata.DebugBackgroundColor = "White"
    >>>> $host.privatedata.VerboseForegroundColor = "Black"
    >>>> $host.privatedata.VerboseBackgroundColor = "White"
    >>>> $host.privatedata.ProgressForegroundColor = "Black"
    >>>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>> }
    >>>> # cls
    >>>> "WindowsPowerShell\profile.ps1"
    >>>> <# #>
    >>>>
    >>>> When it runs, I get this on the screen
    >>>>
    >>>> Windows PowerShell V2 (Community Technology Preview - Features
    >>>> Subject ...
    >>>> Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >>>>
    >>>> # use black on white for all text
    >>>> # --------------------------------
    >>>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>>> $host.privatedata.ErrorForegroundColor = "Black"
    >>>> $host.privatedata.ErrorBackgroundColor = "White"
    >>>> $host.privatedata.WarningForegroundColor = "Black"
    >>>> $host.privatedata.WarningBackgroundColor = "White"
    >>>> $host.privatedata.DebugForegroundColor = "Black"
    >>>> $host.privatedata.DebugBackgroundColor = "White"
    >>>> $host.privatedata.VerboseForegroundColor = "Black"
    >>>> $host.privatedata.VerboseBackgroundColor = "White"
    >>>> $host.privatedata.ProgressForegroundColor = "Black"
    >>>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>>
    >>>> WindowsPowerShell\profile.ps1
    >>>> PS C:\Documents and Settings\Larry>
    >>>>
    >>>> Why do I get that exact output? None of the statements that set color
    >>>> executed,
    >>>> but their source was echoed to the screen.
    >>>>
    >>>
    >>> The reason why it's just printed out is because all you did was create
    >>> an anonymous script block. The if statement executes a scriptblock,
    >>> but you didn't tell PowerShell to do anything with the scriptblock, so
    >>> it just output the contents as the default output for that object type.
    >> >
    >>
    >> In my case the if statement was commented out.
    >> I did not get the side-effects of the color settings.
    >> But I did get the source pf the script block written to the screen.
    >>
    >> - Larry
    >>

      My System SpecsSystem Spec

  7. #7


    Bob Landau Guest

    Re: what just happened?

    Larry,

    You really should get Bruces book. While I don't recomend it as a begining
    tutorial it is a very good advanced tutorial and beyond.

    To really understand why {0/0} you'd need to be familar with how a
    compiler/interpreter is written (not me). Nevertheless Bruce does a nice job
    of explaining this to the rest of us. Its called constant expression folding
    see page 257.

    Basically an expression which is just numerical constants are evaluated at
    compile time not runtime.
    "Larry__Weiss" wrote:

    > It was just an accident in refactoring that code that produced it, nothing
    > intentional. Nevertheless, I wanted to understand it.
    > Thanks for the explanation.
    >
    > I went further and played with constructions like
    > { 0/0 }
    > I don't understand why that expression throws an error if it is not actually
    > executed.
    >
    > - Larry
    >
    >
    >
    > Joel Bennett wrote:

    > > If you write a scriptblock like { write-host "Hello World" } ... it is
    > > an object. PowerShell is, essentially, a functional language in this
    > > respect: the ScriptBlock/Function is a first-class object. By default,
    > > it's .ToString() is the contents, which is what you're seeing.
    > >
    > > If you want it to be EXECUTED instead of output to the pipeline as an
    > > object, you need the CALL operator: &{ Write-Host "Hello World" } ...
    > > (or you can just uncomment the IF($true) that you've got there ;-)
    > > --
    > > Joel
    > >
    > > Larry__Weiss wrote:

    > >> tojo2000 wrote:
    > >>> On Jul 19, 2:03 pm, Larry__Weiss <l...@xxxxxx> wrote:
    > >>>> I was playing around with ways to quickly turn on and off sections
    > >>>> of my
    > >>>> profile.ps1 and at one time ended up with this content (everything
    > >>>> indented 4
    > >>>> spaces)
    > >>>>
    > >>>> <# Larry's PowerShell profile #>
    > >>>> <# #>
    > >>>> # if (1)
    > >>>> {
    > >>>> # use black on white for all text
    > >>>> # --------------------------------
    > >>>> $Host.Ui.RawUi.BackGroundColor = "White"
    > >>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    > >>>> $host.privatedata.ErrorForegroundColor = "Black"
    > >>>> $host.privatedata.ErrorBackgroundColor = "White"
    > >>>> $host.privatedata.WarningForegroundColor = "Black"
    > >>>> $host.privatedata.WarningBackgroundColor = "White"
    > >>>> $host.privatedata.DebugForegroundColor = "Black"
    > >>>> $host.privatedata.DebugBackgroundColor = "White"
    > >>>> $host.privatedata.VerboseForegroundColor = "Black"
    > >>>> $host.privatedata.VerboseBackgroundColor = "White"
    > >>>> $host.privatedata.ProgressForegroundColor = "Black"
    > >>>> $host.privatedata.ProgressBackgroundColor = "White"
    > >>>> }
    > >>>> # cls
    > >>>> "WindowsPowerShell\profile.ps1"
    > >>>> <# #>
    > >>>>
    > >>>> When it runs, I get this on the screen
    > >>>>
    > >>>> Windows PowerShell V2 (Community Technology Preview - Features
    > >>>> Subject ...
    > >>>> Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    > >>>>
    > >>>> # use black on white for all text
    > >>>> # --------------------------------
    > >>>> $Host.Ui.RawUi.BackGroundColor = "White"
    > >>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    > >>>> $host.privatedata.ErrorForegroundColor = "Black"
    > >>>> $host.privatedata.ErrorBackgroundColor = "White"
    > >>>> $host.privatedata.WarningForegroundColor = "Black"
    > >>>> $host.privatedata.WarningBackgroundColor = "White"
    > >>>> $host.privatedata.DebugForegroundColor = "Black"
    > >>>> $host.privatedata.DebugBackgroundColor = "White"
    > >>>> $host.privatedata.VerboseForegroundColor = "Black"
    > >>>> $host.privatedata.VerboseBackgroundColor = "White"
    > >>>> $host.privatedata.ProgressForegroundColor = "Black"
    > >>>> $host.privatedata.ProgressBackgroundColor = "White"
    > >>>>
    > >>>> WindowsPowerShell\profile.ps1
    > >>>> PS C:\Documents and Settings\Larry>
    > >>>>
    > >>>> Why do I get that exact output? None of the statements that set color
    > >>>> executed,
    > >>>> but their source was echoed to the screen.
    > >>>>
    > >>>
    > >>> The reason why it's just printed out is because all you did was create
    > >>> an anonymous script block. The if statement executes a scriptblock,
    > >>> but you didn't tell PowerShell to do anything with the scriptblock, so
    > >>> it just output the contents as the default output for that object type.
    > >> >
    > >>
    > >> In my case the if statement was commented out.
    > >> I did not get the side-effects of the color settings.
    > >> But I did get the source pf the script block written to the screen.
    > >>
    > >> - Larry
    > >>
    >

      My System SpecsSystem Spec

  8. #8


    Larry__Weiss Guest

    Re: what just happened?

    Thanks! Interesting.

    I tried to give it something else "obvious" like
    { 0/($n-$n) }
    { $n=0; 0/$n }
    and it had to wait until execution time to raise the error.
    These, of course, involve variables and not just constants.

    I wanted to wait for a PowerShell V2 version of Bruce's book, but since it is
    not scheduled to be available until January 2010, I will have to go ahead and
    buy the current one, or I'll drive you away with all my questions!

    - Larry


    Bob Landau wrote:

    > Larry,
    > You really should get Bruce's book. While I don't recommend it as a beginning
    > tutorial it is a very good advanced tutorial and beyond.
    >
    > To really understand why {0/0} you'd need to be familiar with how a
    > compiler/interpreter is written (not me). Nevertheless Bruce does a nice job
    > of explaining this to the rest of us. Its called constant expression folding
    > see page 257.
    >
    > Basically an expression which is just numerical constants are evaluated at
    > compile time not runtime.
    >
    > "Larry__Weiss" wrote:

    >> It was just an accident in refactoring that code that produced it, nothing
    >> intentional. Nevertheless, I wanted to understand it.
    >> Thanks for the explanation.
    >> I went further and played with constructions like
    >> { 0/0 }
    >> I don't understand why that expression throws an error if it is not actually
    >> executed.
    >>
    >> Joel Bennett wrote:

    >>> If you write a scriptblock like { write-host "Hello World" } ... it is
    >>> an object. PowerShell is, essentially, a functional language in this
    >>> respect: the ScriptBlock/Function is a first-class object. By default,
    >>> it's .ToString() is the contents, which is what you're seeing.
    >>>
    >>> If you want it to be EXECUTED instead of output to the pipeline as an
    >>> object, you need the CALL operator: &{ Write-Host "Hello World" } ...
    >>> (or you can just uncomment the IF($true) that you've got there ;-)
    >>>
    >>> Larry__Weiss wrote:
    >>>> In my case the if statement was commented out.
    >>>> I did not get the side-effects of the color settings.
    >>>> But I did get the source pf the script block written to the screen.
    >>>>
    >>>> tojo2000 wrote:
    >>>>> The reason why it's just printed out is because all you did was create
    >>>>> an anonymous script block. The if statement executes a scriptblock,
    >>>>> but you didn't tell PowerShell to do anything with the scriptblock, so
    >>>>> it just output the contents as the default output for that object type.
    >>>>
    >>>>> On Jul 19, 2:03 pm, Larry__Weiss <l...@xxxxxx> wrote:
    >>>>>> I was playing around with ways to quickly turn on and off sections
    >>>>>> of my
    >>>>>> profile.ps1 and at one time ended up with this content (everything
    >>>>>> indented 4
    >>>>>> spaces)
    >>>>>>
    >>>>>> <# Larry's PowerShell profile #>
    >>>>>> <# #>
    >>>>>> # if (1)
    >>>>>> {
    >>>>>> # use black on white for all text
    >>>>>> # --------------------------------
    >>>>>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>>>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>>>>> $host.privatedata.ErrorForegroundColor = "Black"
    >>>>>> $host.privatedata.ErrorBackgroundColor = "White"
    >>>>>> $host.privatedata.WarningForegroundColor = "Black"
    >>>>>> $host.privatedata.WarningBackgroundColor = "White"
    >>>>>> $host.privatedata.DebugForegroundColor = "Black"
    >>>>>> $host.privatedata.DebugBackgroundColor = "White"
    >>>>>> $host.privatedata.VerboseForegroundColor = "Black"
    >>>>>> $host.privatedata.VerboseBackgroundColor = "White"
    >>>>>> $host.privatedata.ProgressForegroundColor = "Black"
    >>>>>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>>>> }
    >>>>>> # cls
    >>>>>> "WindowsPowerShell\profile.ps1"
    >>>>>> <# #>
    >>>>>>
    >>>>>> When it runs, I get this on the screen
    >>>>>>
    >>>>>> Windows PowerShell V2 (Community Technology Preview - Features
    >>>>>> Subject ...
    >>>>>> Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >>>>>>
    >>>>>> # use black on white for all text
    >>>>>> # --------------------------------
    >>>>>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>>>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>>>>> $host.privatedata.ErrorForegroundColor = "Black"
    >>>>>> $host.privatedata.ErrorBackgroundColor = "White"
    >>>>>> $host.privatedata.WarningForegroundColor = "Black"
    >>>>>> $host.privatedata.WarningBackgroundColor = "White"
    >>>>>> $host.privatedata.DebugForegroundColor = "Black"
    >>>>>> $host.privatedata.DebugBackgroundColor = "White"
    >>>>>> $host.privatedata.VerboseForegroundColor = "Black"
    >>>>>> $host.privatedata.VerboseBackgroundColor = "White"
    >>>>>> $host.privatedata.ProgressForegroundColor = "Black"
    >>>>>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>>>>
    >>>>>> WindowsPowerShell\profile.ps1
    >>>>>> PS C:\Documents and Settings\Larry>
    >>>>>>
    >>>>>> Why do I get that exact output? None of the statements that set color
    >>>>>> executed,
    >>>>>> but their source was echoed to the screen.
    >>>>>>

      My System SpecsSystem Spec

  9. #9


    Larry__Weiss Guest

    PowerShell V2 books

    At least Bruce's V2 book will finalize after V2 is finalized.

    Blog entries like the one below indicate some final decisions have been reached
    for PS V2 and are being communicated.
    http://blogs.msdn.com/powershell/arc...shell-2-0.aspx

    - Larry

    Larry__Weiss wrote:

    > I wanted to wait for a PowerShell V2 version of Bruce's book, but since
    > it is not scheduled to be available until January 2010, I will have to
    > go ahead and buy the current one, or I'll drive you away with all my
    > questions!
    >
    > Bob Landau wrote:

    >> Larry, You really should get Bruce's book. While I don't recommend it
    >> as a beginning tutorial it is a very good advanced tutorial and beyond.
    >>

      My System SpecsSystem Spec

  10. #10


    Hans Dingemans Guest

    Re: what just happened?

    According Manning's site:

    Or buy the Early Access Edition now, receive the paper version of the V2
    book in January, and receive the ebook of the current version. I presume you
    get two ebooks now: the current and the V2 as it progresses towards
    completion.

    http://www.manning.com/payette2/




    "Larry__Weiss" <lfw@xxxxxx> wrote in message
    news:O8sBZUVCKHA.5040@xxxxxx

    > Thanks! Interesting.
    >
    > I tried to give it something else "obvious" like
    > { 0/($n-$n) }
    > { $n=0; 0/$n }
    > and it had to wait until execution time to raise the error.
    > These, of course, involve variables and not just constants.
    >
    > I wanted to wait for a PowerShell V2 version of Bruce's book, but since it
    > is not scheduled to be available until January 2010, I will have to go
    > ahead and buy the current one, or I'll drive you away with all my
    > questions!
    >
    > - Larry
    >
    >
    > Bob Landau wrote:

    >> Larry, You really should get Bruce's book. While I don't recommend it as
    >> a beginning tutorial it is a very good advanced tutorial and beyond.
    >>
    >> To really understand why {0/0} you'd need to be familiar with how a
    >> compiler/interpreter is written (not me). Nevertheless Bruce does a nice
    >> job of explaining this to the rest of us. Its called constant expression
    >> folding see page 257.
    >>
    >> Basically an expression which is just numerical constants are evaluated
    >> at compile time not runtime.
    > >
    >> "Larry__Weiss" wrote:

    >>> It was just an accident in refactoring that code that produced it,
    >>> nothing intentional. Nevertheless, I wanted to understand it.
    >>> Thanks for the explanation.
    >>> I went further and played with constructions like
    >>> { 0/0 }
    >>> I don't understand why that expression throws an error if it is not
    >>> actually executed.
    >>>
    >>> Joel Bennett wrote:
    >>>> If you write a scriptblock like { write-host "Hello World" } ... it is
    >>>> an object. PowerShell is, essentially, a functional language in this
    >>>> respect: the ScriptBlock/Function is a first-class object. By default,
    >>>> it's .ToString() is the contents, which is what you're seeing.
    >>>>
    >>>> If you want it to be EXECUTED instead of output to the pipeline as an
    >>>> object, you need the CALL operator: &{ Write-Host "Hello World" } ...
    >>>> (or you can just uncomment the IF($true) that you've got there ;-)
    >>>>
    >>>> Larry__Weiss wrote:
    >>>>> In my case the if statement was commented out.
    >>>>> I did not get the side-effects of the color settings.
    >>>>> But I did get the source pf the script block written to the screen.
    >>>>>
    >>>>> tojo2000 wrote:
    >>>>>> The reason why it's just printed out is because all you did was
    >>>>>> create
    >>>>>> an anonymous script block. The if statement executes a scriptblock,
    >>>>>> but you didn't tell PowerShell to do anything with the scriptblock,
    >>>>>> so
    >>>>>> it just output the contents as the default output for that object
    >>>>>> type.
    >>>>>
    >>>>>> On Jul 19, 2:03 pm, Larry__Weiss <l...@xxxxxx> wrote:
    >>>>>>> I was playing around with ways to quickly turn on and off sections
    >>>>>>> of my
    >>>>>>> profile.ps1 and at one time ended up with this content (everything
    >>>>>>> indented 4
    >>>>>>> spaces)
    >>>>>>>
    >>>>>>> <# Larry's PowerShell profile #>
    >>>>>>> <# #>
    >>>>>>> # if (1)
    >>>>>>> {
    >>>>>>> # use black on white for all text
    >>>>>>> # --------------------------------
    >>>>>>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>>>>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>>>>>> $host.privatedata.ErrorForegroundColor = "Black"
    >>>>>>> $host.privatedata.ErrorBackgroundColor = "White"
    >>>>>>> $host.privatedata.WarningForegroundColor = "Black"
    >>>>>>> $host.privatedata.WarningBackgroundColor = "White"
    >>>>>>> $host.privatedata.DebugForegroundColor = "Black"
    >>>>>>> $host.privatedata.DebugBackgroundColor = "White"
    >>>>>>> $host.privatedata.VerboseForegroundColor = "Black"
    >>>>>>> $host.privatedata.VerboseBackgroundColor = "White"
    >>>>>>> $host.privatedata.ProgressForegroundColor = "Black"
    >>>>>>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>>>>> }
    >>>>>>> # cls
    >>>>>>> "WindowsPowerShell\profile.ps1"
    >>>>>>> <# #>
    >>>>>>>
    >>>>>>> When it runs, I get this on the screen
    >>>>>>>
    >>>>>>> Windows PowerShell V2 (Community Technology Preview - Features
    >>>>>>> Subject ...
    >>>>>>> Copyright (C) 2008 Microsoft Corporation. All rights reserved.
    >>>>>>>
    >>>>>>> # use black on white for all text
    >>>>>>> # --------------------------------
    >>>>>>> $Host.Ui.RawUi.BackGroundColor = "White"
    >>>>>>> $Host.Ui.RawUi.ForeGroundColor = "Black"
    >>>>>>> $host.privatedata.ErrorForegroundColor = "Black"
    >>>>>>> $host.privatedata.ErrorBackgroundColor = "White"
    >>>>>>> $host.privatedata.WarningForegroundColor = "Black"
    >>>>>>> $host.privatedata.WarningBackgroundColor = "White"
    >>>>>>> $host.privatedata.DebugForegroundColor = "Black"
    >>>>>>> $host.privatedata.DebugBackgroundColor = "White"
    >>>>>>> $host.privatedata.VerboseForegroundColor = "Black"
    >>>>>>> $host.privatedata.VerboseBackgroundColor = "White"
    >>>>>>> $host.privatedata.ProgressForegroundColor = "Black"
    >>>>>>> $host.privatedata.ProgressBackgroundColor = "White"
    >>>>>>>
    >>>>>>> WindowsPowerShell\profile.ps1
    >>>>>>> PS C:\Documents and Settings\Larry>
    >>>>>>>
    >>>>>>> Why do I get that exact output? None of the statements that set
    >>>>>>> color
    >>>>>>> executed,
    >>>>>>> but their source was echoed to the screen.
    >>>>>>>

      My System SpecsSystem Spec

what just happened? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
What has happened to it. Emmett8324 Browsers & Mail 3 17 Feb 2009
Help--what happened to 6GB? chanook*xyz* Vista General 4 30 Sep 2008
What Happened???? Jeremy Olson Vista General 2 15 Nov 2007
I Know what happened - Just FYI Bill Yanaire Vista General 0 13 Aug 2007
What happened? DCR Vista General 15 23 Dec 2006