dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.39k stars 788 forks source link

Install-DbaMaintenanceSolution does not work inside a container #9252

Closed david-garcia-garcia closed 4 months ago

david-garcia-garcia commented 4 months ago

Please read -- recent changes to our repo

On November 10, 2022, we removed some bloat from our repository (for the second and final time). This change requires that all contributors reclone or refork their repo.

PRs from repos that have not been recently reforked or recloned will be closed and @potatoqualitee will cherry-pick your commits and open a new PR with your changes.

Type of Change

[X] Bug fix (non-breaking change, fixes # )

Purpose

Fix internet connection check inside windows containers

Approach

Remove uneeded internet connection check prior to download attempt. Current implementation already does fallback to embedded maintenance solution if download fails, so there is no need pre-check.

Inside a windows container, see output of current commands used to pre-check if an internet connection is available.

PS C:\> Get-NetConnectionProfile
Get-NetConnectionProfile : A general error occurred that is not covered by a 
more specific error code.
At line:1 char:1
+ Get-NetConnectionProfile
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_NetConnectionProfile:root/St 
   andardCi...nnectionProfile) [Get-NetConnectionProfile], CimException
    + FullyQualifiedErrorId : MI RESULT 1,Get-NetConnectionProfile

PS C:\> $network = [Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
PS C:\> 
      >                     $script:internet = ([Activator]::CreateInstance($network)).GetNetworkConnections() | ForEach-Object { $_.GetNetwork().GetConnectivity() } | Where-Object { ($_ -band 64) -eq 64 }
The service cannot be started, either because it is disabled or because it has 
    + CategoryInfo          : OperationStopped: (:) [], COMException~~~~~~~     
PS C:\>ullyQualifiedErrorId : System.Runtime.InteropServices.COMException       
+ ...             $script:internet = ([Activator]::CreateInstance($network) ... 

Commands to test

Install-DbaMaintenanceSolution

Screenshots

Learning

potatoqualitee commented 4 months ago

Thank you for your contribution, David! This fix is a bit severe. I believe when it's removed, and an internet connection does not exist, it's a bunch of red.

Instead, can you please add it back then throw an -ErrorAction SilentlyContinue on that second Get-NetConnectionProfile. See if that works better.

potatoqualitee commented 4 months ago

Thank you! Please let me know if this does not solve your problem.

david-garcia-garcia commented 4 months ago

Working now! Thanks for your help.