ErrorVariable in splating not populated with errors

The following code produces errors, I set EA to “SilentlyContinue” to not show errors but instead save them to ErrorVariable:

		$UpdateParams = @{
			ErrorVariable = "UpdateError"
			ErrorAction = "SilentlyContinue"
		}
        # This will surely generate errors in Windows PowerShell
        Update-Help @UpdateParams

        # Show errors manually: (doesn't work)
        $UpdateParams["ErrorVariable"]

Output is just a variable name:

UpdateError

Expected output:

The actual errors

I want to capture errors without displaying them in this code but as you can see it doesn’t work

It looks like you created a hash table and are calling a specific key at the end, which is returning the expected value. If you call $UpdateError (add $ to get the variable content) you get the error information.

Or, perhaps I am misunderstanding.

2 Likes

You have a keen eye. Yes the variable you place as a string in -*Variable is the variable name. You access it with $ variable name like any other variable.

Interesting, I thought we need to reference hashtable when accesing it’s elements, I didn’t know elements are visible in current scope without referencing the hashtable.

thanks.