PlagueHO / CosmosDB

PowerShell Module for working with Azure Cosmos DB databases, collections, documents, attachments, offers, users, permissions, triggers, stored procedures and user defined functions.
http://dscottraynsford.com
MIT License
156 stars 46 forks source link

CmdLets do not honor $ProgressPreference #308

Open jamie-tillman opened 5 years ago

jamie-tillman commented 5 years ago

When I run CosmosDB cmdlets (specifically the New-CosmosDbDocument cmdlet), there is a flash of a Powershell status bar:

Reading Web Response
   Reading response stream... (Number of bytes read: ####)

This is pretty likely coming from Invoke-WebRequest calls that are being performed within the wrappings of the CosmosDB module. Unfortunately, I've set $ProgressPreference to "SilentlyContinue" and it still does this. If I run a standard Invoke-WebRequest call instead, it honors the setting. It appears something in the CosmosDB code is disrupting the proper handling of this setting.

Tech details:

CosmosDB Module version 3.5.0.426
Name             : ConsoleHost
Version          : 5.1.18362.145
InstanceId       : 503b95f0-ff1d-49d5-b651-5b7603b53671
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
jamie-tillman commented 5 years ago

As I have other progress bars running in my scripts, I would prefer the ability to disable this particular progress display with a specific parameter. I realize that may not be appropriate Powershell etiquette, however.

PlagueHO commented 5 years ago

Hi @jamie-tillman - good catch and thanks for raising this. $ProgressPreference should be supported here. I'll see what is going on and submit a fix this weekend.

PlagueHO commented 5 years ago

I'm having trouble identifying the cause of this. If I place a Write-Verbose -Message ("Progress Preference = $ProgressPreference") -Verbose right before the call to Invoke-WebRequest in Invoke-CosmosDbRequest then it does show that the $ProgressPreference variable is visible to the CosmosDB function.

Can you try setting $global:ProgressPreference = 'SilentlyContinue' and see if that suppresses it?

jamie-tillman commented 5 years ago

This is very strange. I can't recreate it now! I'm using the Azure Emulator and I'm loading documents in a loop, and had noticed the problem only kicked in after several hundred iterations. Perhaps my system at the time I was observing this was being slowed down, which would have caused the WebRequest progress to be shown because of the delay in http response.

I'll try to find a moment to add process loads to my system and see if that slows the response rate down. Or perhaps I could try loading some larger documents.

jamie-tillman commented 5 years ago

Aha, my container re-creation script takes more time and did raise the progress display ever so briefly. Your suspicion was correct. Setting $global:ProgressPreference = 'SilentlyContinue' does work to suppress it. Setting $ProgressPreference instead does not.

Using the $global option will actually work fine for my purposes, as I can simply set it and unset it as I perform the New-CosmosDbDocument calls.

Thanks for that!