chocolatey / chocolatey-licensed-issues

Issues for Licensed Editions of Chocolatey
19 stars 13 forks source link

Failing to load PowerShell module on the second try #363

Open sync-by-unito[bot] opened 6 months ago

sync-by-unito[bot] commented 6 months ago

What You Are Seeing?

When using an Advanced Deployment step in Chocolatey Central Management, installed PowerShell modules throw an error when attempting to load into the PowerShell host after the first time at doing so.

What is Expected?

Advanced Deployment step code is executed on a target machine every time it is needed

How Did You Get This To Happen? (Steps to Reproduce)

To reproduce, run the following deployment against your targets twice

  1. Import Agent_PowerShell_Host_Test.json into CCM
  2. Add target Group to advanced step
  3. Save Deployment
  4. Move Deployment to ready
  5. Run deployment
  6. When deployment is finished, duplicate deployment
  7. Move duplicated deployment to ready
  8. Run duplicated deployment
  9. Examine errors after second attempt

System Details

Output Log

error.log

~~~sh 2023-11-27 19:13:27,989 [DEBUG ] - Calling Chocolatey PowerShell agent (tag: '34') 2023-11-27 19:13:27,989 [DEBUG ] - Running the following (may differ slightly from provided): ## 2023-11-27 19:13:27,989 [DEBUG ] - $hostname = hostname Write-Host "Hostname: $hostname" Import-Module NetSecurity -Force Get-NetFirewallSetting -PolicyStore ActiveStore | Select-Object -ExpandProperty ActiveProfile ## exit $LASTEXITCODE 2023-11-27 19:13:28,035 [INFO ] - Hostname: DemoServer 2023-11-27 19:13:28,035 [VERBOSE] - Loading module from path 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetSecurity\NetSecurity.psd1'. 2023-11-27 19:13:28,035 [VERBOSE] - Loading 'TypesToProcess' from path 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetSecurity\NetSecurity.types.ps1xml'. 2023-11-27 19:13:28,035 [VERBOSE] - Loading 'FormatsToProcess' from path 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetSecurity\NetSecurity.formats.ps1xml'. 2023-11-27 19:13:28,066 [VERBOSE] - Loading module from path 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetSecurity\Microsoft.Windows.Firewall.Commands.dll'. 2023-11-27 19:13:28,066 [ERROR ] - Value cannot be null. Parameter name: source at , : line 3 2023-11-27 19:13:28,066 [DEBUG ] - Chocolatey PowerShell agent exited with '1'. ~~~

Workarounds

  1. Restart the agent service on the failing endpoint(s).

Proposed Solution

Related Issues and Tickets

Done Checklist

TBD

┆Issue is synchronized with this Gitlab issue by Unito