Re: When do i need [void]?
- From: "Jeffrey Snover [MSFT]" <jsnover@xxxxxxxxxxxxx>
- Date: Sun, 20 Nov 2005 16:14:26 -0800
You can always rely upon a SCOPE to make this work a little easier:
MSH> &{$erroractionPreference = "silentlycontinue"; spps 43};spps 23
stop-process : No process with process ID 23 was found.
At line:1 char:61
+ &{$erroractionPreference = "silentlycontinue"; spps 43};spps <<<< 23
MSH>
&{} runs a the enclosed code in a new SCOPE.
Setting $ErrorActionPreference in the new scope creates a COPY of the
variable to be used in that scope. This is why the "spps 43" does not
generate an error message.
Exiting the scope tosses the variable so you get the original value which is
why spps 23 generates an error.
--
Jeffrey Snover [MSFT]
Monad Architect
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.
"/\/\o\/\/" <no@xxxxxxxx> wrote in message
news:uCSfTMg7FHA.1864@xxxxxxxxxxxxxxxxxxxxxxx
> DontBotherMeWithSpam wrote:
>> Bah, in my script, in the beginning i would set $ErrorActionPreference
>> = "SilentlyContinue" and in the end set the $ErrorActionPreference to
>> its original value instead of having to specifiy that "-ErrorAction"
>> parameter each time :)
>>
> Depending on your need,
>
> If this is the only time you dont want to see an error, my option is more
> handy, it you don't care about any error in your script, yours is better
> ;-)
>
> as this is ugly too :
>
> MSH>$ErrorActionPreference = "SilentlyContinue"
> MSH>new-item -type file testing.txt
> MSH>$ErrorActionPreference = "Continue"
>
>
> gr /\/\o\/\/
.
- References:
- [MSH] When do i need [void]?
- From: DontBotherMeWithSpam
- Re: [MSH] When do i need [void]?
- From: /\\/\\o\\/\\/
- Re: When do i need [void]?
- From: DontBotherMeWithSpam
- Re: When do i need [void]?
- From: /\\/\\o\\/\\/
- Re: When do i need [void]?
- From: DontBotherMeWithSpam
- Re: When do i need [void]?
- From: /\\/\\o\\/\\/
- [MSH] When do i need [void]?
- Prev by Date: Re: output of append command of stringbuilder
- Next by Date: Re: create a share folder on a remote computer
- Previous by thread: Re: When do i need [void]?
- Next by thread: Re: When do i need [void]?
- Index(es):
Relevant Pages
|