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
>