This is a cross-post with PowerShell/PowerShell: Execution Policy RemoteSigned interpreted differently in pwsh7.1 / Unblock-File does not work #13869
1. General summary of the issue
invoking Pester in Pwsh 7 with default Execution Policy (RemoteSigned) on files on a local Server results in Errors because File is not digitally signed. Unblocking the file does not help.
2. Describe Your Environment
Pester version : 5.1.0 C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psd1
PowerShell version : 5.1.19041.546
OS version : Microsoft Windows NT 10.0.19041.0
3. Expected Behavior
Same environment, when my code base is on my local machine. Works.
Same environment in PowerShell 5.1. Works:
invoke-pester
Starting discovery in 4 files.
Discovery finished in 469ms.
Testing 'TeamsFunctions' in path '\\SERVERNAME\Share\Code\Personal\TeamsFunctions'
[ASSERT ] ERROR: You must call the Connect-SkypeOnline cmdlet before calling any other cmdlets.
[ASSERT ] INFO: Connect-Me can be used to disconnect, then connect to SkypeOnline, AzureAD & MicrosoftTeams in one step!
[ASSERT ] ERROR: You must call the Connect-SkypeOnline cmdlet before calling any other cmdlets.
[ASSERT ] INFO: Connect-Me can be used to disconnect, then connect to SkypeOnline, AzureAD & MicrosoftTeams in one step!
[+] Enable-TeamsUserForEnterpriseVoice.Tests.ps1 89ms (11ms|59ms)
[+] Show-FunctionStatus.Tests.ps1 89ms (2ms|68ms)
[+] Format-StringForUse.Tests.ps1 173ms (84ms|65ms)
Tests completed in 12.66s
Tests Passed: 779, Failed: 0, Skipped: 0 NotRun: 0
4.Current Behavior
invoke-pester
Starting discovery in 4 files.
System.Management.Automation.PSSecurityException: File \\SERVERNAME\Share\Code\Personal\TeamsFunctions\Private\Tests\Enable-TeamsUserForEnterpriseVoice.Tests.ps1 cannot be loaded. The file \\SERVERNAME\Share\Code\Personal\TeamsFunctions\Private\Tests\Enable-TeamsUserForEnterpriseVoice.Tests.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
---> System.UnauthorizedAccessException: File \\SERVERNAME\Share\Code\Personal\TeamsFunctions\Private\Tests\Enable-TeamsUserForEnterpriseVoice.Tests.ps1 cannot be loaded. The file \\SERVERNAME\Share\Code\Personal\TeamsFunctions\Private\Tests\Enable-TeamsUserForEnterpriseVoice.Tests.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 2899
at Invoke-File, C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 2908
at Invoke-BlockContainer, C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 2833
at Discover-Test, C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 1407
at Invoke-Test, C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 2352
at Invoke-Pester<End>, C:\Program Files\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 4753
at <ScriptBlock>, <No file>: line 1
5. Possible Solution
I don't know where the issue here lies, but as the same test works on PowerShell 5.1, I presume it to be related to PowerShell not Pester. Just posting it here for awareness.
Would it be safe to incorporate Unblock-File for all discovered files? (Provided it works?)
6. Context
trying to run Pester tests on PowerShell 7
This is a cross-post with PowerShell/PowerShell: Execution Policy RemoteSigned interpreted differently in pwsh7.1 / Unblock-File does not work #13869
1. General summary of the issue
invoking Pester in Pwsh 7 with default Execution Policy (RemoteSigned) on files on a local Server results in Errors because File is not digitally signed. Unblocking the file does not help.
2. Describe Your Environment
3. Expected Behavior
Same environment, when my code base is on my local machine. Works.
Same environment in PowerShell 5.1. Works:
4.Current Behavior
5. Possible Solution
I don't know where the issue here lies, but as the same test works on PowerShell 5.1, I presume it to be related to PowerShell not Pester. Just posting it here for awareness.
Would it be safe to incorporate Unblock-File for all discovered files? (Provided it works?)
6. Context
trying to run Pester tests on PowerShell 7