@@ -99,10 +99,10 @@ internal void InvokeProfile(string profilePath)
9999 try
100100 {
101101 // Import-Module on a .ps1 file will evaluate the script in the global scope.
102- _pwsh . AddCommand ( "Microsoft.PowerShell.Core \\ Import-Module" )
102+ _pwsh . AddCommand ( Utils . ImportModuleCmdletInfo )
103103 . AddParameter ( "Name" , profilePath )
104104 . AddParameter ( "PassThru" , true )
105- . AddCommand ( "Microsoft.PowerShell.Core \\ Remove-Module" )
105+ . AddCommand ( Utils . RemoveModuleCmdletInfo )
106106 . AddParameter ( "Force" , true )
107107 . AddParameter ( "ErrorAction" , "SilentlyContinue" )
108108 . InvokeAndClearCommands ( ) ;
@@ -144,7 +144,7 @@ internal Hashtable InvokeFunction(
144144 {
145145 // If an entry point is defined, we import the script module.
146146 moduleName = Path . GetFileNameWithoutExtension ( scriptPath ) ;
147- _pwsh . AddCommand ( "Microsoft.PowerShell.Core \\ Import-Module" )
147+ _pwsh . AddCommand ( Utils . ImportModuleCmdletInfo )
148148 . AddParameter ( "Name" , scriptPath )
149149 . InvokeAndClearCommands ( ) ;
150150
@@ -206,12 +206,19 @@ private void ResetRunspace(string moduleName)
206206 if ( ! string . IsNullOrEmpty ( moduleName ) )
207207 {
208208 // If the function had an entry point, this will remove the module that was loaded
209- _pwsh . AddCommand ( "Microsoft.PowerShell.Core \\ Remove-Module" )
209+ _pwsh . AddCommand ( Utils . RemoveModuleCmdletInfo )
210210 . AddParameter ( "Name" , moduleName )
211211 . AddParameter ( "Force" , true )
212212 . AddParameter ( "ErrorAction" , "SilentlyContinue" )
213213 . InvokeAndClearCommands ( ) ;
214214 }
215+
216+ // Clean up jobs started during the function execution.
217+ _pwsh . AddCommand ( Utils . GetJobCmdletInfo )
218+ . AddCommand ( Utils . RemoveJobCmdletInfo )
219+ . AddParameter ( "Force" , true )
220+ . AddParameter ( "ErrorAction" , "SilentlyContinue" )
221+ . InvokeAndClearCommands ( ) ;
215222 }
216223 }
217224}
0 commit comments