The trying to prevent the (apparently default) Inquire mode in WriteDebug and this does not work (See earlier post). As I do not yet know how to detect if -DEBUG is set on the command line I am trying this:
(<Cmdlet(VerbsDiagnostic.Test, "MyCmdlet", SupportsShouldProcess:=False)> _
Protected Overrides Sub BeginProcessing()
setting = SessionState.PSVariable
dbPref = setting.Get("DebugPreference").Value
vbPref = setting.Get("VerbosePreference").Value
WriteObject("VBpref: " & vbPref.ToString)
WriteObject("DBpref: " & dbPref.ToString)
setting.Set("VerbosePreference", ActionPreference.Continue)
setting.Set("DebugPreference", ActionPreference.Continue)
dbPref = setting.Get("DebugPreference").Value
vbPref = setting.Get("VerbosePreference").Value
WriteObject("VBpref: " & vbPref.ToString)
WriteObject("DBpref: " & dbPref.ToString)
WriteDebug("TEST")
The ouput is as follows:
PS> Test-MyCmdlet -d
VBpref: SilentlyContinue
DBpref: SilentlyContinue
VBpref: Continue
DBpref: Continue
DEBUG: TEST
Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help
(default is "Y"):
And this is the output without the -D switch (no Inquire):
PS> Test-MyCmdlet
VBpref: SilentlyContinue
DBpref: SilentlyContinue
VBpref: Continue
DBpref: Continue
DEBUG: TEST
So why, if the reset above has worked, am I still in Inquire mode? And how can I change it?