PowerShell 2.0 and Write-Verbose strange behaviour

I was writting a script for work wich was invoked on Windows 2012 R2 with PowerShell 4.0 as well on Windows 2008 R2 with PowerShell 2.0. This script was calling some sg utils and comparing the results. There is option to call it and to get just the result or to call it with more messges to see what actually is doing. So Write-Verbose seemed as a perfect option. In the first case all works fine with PowerShell (PS) 4.0. For some reason with PS 2.0 in Verbose mode it is failing at some point - sg_vpd cannot be called so instead of string for the result I'm getting null.

Also when the script is called without Verbose works perfectly fine. So it seems the problem is in Write-Verbose. After research in internet I wasn't able to find anything like this an solution to the problem. The only option I came into is to replace the Write-Verbose cmdlet with custom function that behves the same way as the cmdlet just it's not using the verbose pipeline.


function global:Write-Verbose
            Mandatory = $true,
            Position = 0,

        # check $VerbosePreference variable
        if ($VerbosePreference -ne 'SilentlyContinue')
            # do this via Write-Host
            Write-Host "VERBOSE: $Message" -ForegroundColor Yellow


Even though this is workarround and not a real solution to the problem so far works. I guess not so major problem since there is PS 4.0 which doesn't have this problem.



0 #3 fitbit sleep tracker 2015-06-19 00:33
In a production environment a file in the wrong place at the wrong time can come back to bite you somewhere that is not pleasant. Here's a way to avoid that if your environment works anything like mine, with repetition and automation.
0 #2 internet marketing 2015-01-31 10:55
Hello There. I discovered your webloog the use of msn. This is a
very smartly written article. I will be sure to bookmark it and
return to learn mor of youyr helpful information. Thajk you for
the post. I will certainly return.
0 #1 online marketing 2015-01-29 01:51
bookmarked!!, I love your site!

Add comment

Security code

Configure debugging environment for ARM in Ubuntu ...
Configure debugging environment for ARM in Ubuntu with Eclipse

Next article is how to configure SEGGER's J-Link debugger to debug the NuttX OS from Eclipse.  Here I'm going to describe the it using The J-Link hardware debugging Eclipse plug-in. [ ... ]

Building NuttX in Eclipse (Ubuntu)
Building NuttX in Eclipse (Ubuntu)

For me personally is more convenient to build the code directly from the IDE where I'm editing it so here is an article how to configure building of NuttX from Eclipse. I'm configuring [ ... ]

Install and configure NuttX ARM build environment ...
Install and configure NuttX ARM build environment in Linux

In this manual will see how to install and configure all the tools needed to build NuttX for ARM under Linux. The toolchain is the one comming with the Ubuntu itself (at least with the [ ... ]


The program provides quick access to some statistics from the LTCRabbit.com litecoin mining pool.  

Time Tracker
Time Tracker

Time Tracker is a tool to track the time that was spent for some task and how much this time costs. Features:
   - Set the complementary time
   - Set the rate per [ ... ]

Light Control
Light Control

App web site is now http://LightControl.us. Visit us there. Mobile application to control Philips Hue lights. So far it is only for Android. Features:
 - Easy and fast control [ ... ]

LTC: LKjqX7NipWXyPEkt3L3AwiRuCaw7h1hXLw
BTC: 1ApxQc2j4Wz3N7ei4XwYFTh6t4CeYMzbzZ

Go to top