Re: When do i need [void]?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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\/\/


.



Relevant Pages

  • Re: Name collisions in Monad
    ... We spent a lot of time working on the scoping rules in Monad. ... create a new scope when run, and variables _created_ in that new scope are ... script, call a function, or start a new instance of Windows Command ... $var is initially set to "init" in the function ...
    (microsoft.public.windows.server.scripting)
  • Re: Can com+ Hotfix Rollup Package 27 fix my memory problem with WSH. CreateObject/CreateScript?
    ... > these activities have effects that are felt outside of the scope of a script ... Of course in script, the object will be ... > Even the above definition makes no distinction between object variables ... a connection every time I read or write a key, ...
    (microsoft.public.scripting.wsh)
  • Re: One other related Q Re: basic Q: Only one way to make vars live outside of the scope of a functi
    ... >>> directly to the calling script, without having to use global variables ... to get multiple return items from a subprocedure. ... >>> better not to mix scope and use global variables for multiple return ... before terminating the object reference. ...
    (microsoft.public.scripting.vbscript)
  • Re: new to scripting.. the below script stops after first run..
    ... I have exports from my unix servers that aren't compatible with MS for a straight import so I've fiddled with the data, and now I want to just run the same script many times and pass it a bunch of parameters.. ... Echo Changing scope options ... Netsh dhcp server %server% scope %netid% add iprange %iprangestart% %iprangeend% BOTH> NUL ...
    (microsoft.public.windows.server.scripting)
  • Re: [MSH] WMI Help
    ... access the variable in the global scope whether or not the script is ... dot-sourced into the global scope then $script:class is equivalent to ... >> defined so it will search the stack and find it in the parent scope and ...
    (microsoft.public.windows.server.scripting)