@@ -205,12 +205,14 @@ private void SaveModule(PSObject module)
205205 ThrowIfNull ( module , "module" ) ;
206206
207207 // TODO validate module
208- var ps = System . Management . Automation . PowerShell . Create ( ) ;
209- ps . Runspace = runspace ;
210- ps . AddCommand ( "Save-Module" )
211- . AddParameter ( "Path" , tempModulePath )
212- . AddParameter ( "InputObject" , module ) ;
213- ps . Invoke ( ) ;
208+ using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
209+ {
210+ ps . Runspace = runspace ;
211+ ps . AddCommand ( "Save-Module" )
212+ . AddParameter ( "Path" , tempModulePath )
213+ . AddParameter ( "InputObject" , module ) ;
214+ ps . Invoke ( ) ;
215+ }
214216 }
215217
216218 private void SetupPSModulePath ( )
@@ -295,13 +297,15 @@ public PSObject FindModule(string moduleName)
295297 {
296298 return modulesFound [ moduleName ] ;
297299 }
298- var ps = System . Management . Automation . PowerShell . Create ( ) ;
299- Collection < PSObject > modules = null ;
300- ps . Runspace = runspace ;
301- ps . AddCommand ( "Find-Module" , true )
302- . AddParameter ( "Name" , moduleName )
303- . AddParameter ( "Repository" , moduleRepository ) ;
304- modules = ps . Invoke < PSObject > ( ) ;
300+ Collection < PSObject > modules = null ;
301+ using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
302+ {
303+ ps . Runspace = runspace ;
304+ ps . AddCommand ( "Find-Module" , true )
305+ . AddParameter ( "Name" , moduleName )
306+ . AddParameter ( "Repository" , moduleRepository ) ;
307+ modules = ps . Invoke < PSObject > ( ) ;
308+ }
305309 if ( modules == null )
306310 {
307311 return null ;
@@ -345,13 +349,15 @@ public void SaveModule(string moduleName)
345349 {
346350 return ;
347351 }
348- var ps = System . Management . Automation . PowerShell . Create ( ) ;
349- ps . Runspace = runspace ;
350- ps . AddCommand ( "Save-Module" )
351- . AddParameter ( "Path" , tempModulePath )
352- . AddParameter ( "Name" , moduleName )
353- . AddParameter ( "Force" ) ;
354- ps . Invoke ( ) ;
352+ using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
353+ {
354+ ps . Runspace = runspace ;
355+ ps . AddCommand ( "Save-Module" )
356+ . AddParameter ( "Path" , tempModulePath )
357+ . AddParameter ( "Name" , moduleName )
358+ . AddParameter ( "Force" ) ;
359+ ps . Invoke ( ) ;
360+ }
355361 }
356362
357363 /// <summary>
0 commit comments