@@ -205,12 +205,14 @@ private void SaveModule(PSObject module)
205
205
ThrowIfNull ( module , "module" ) ;
206
206
207
207
// 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
+ }
214
216
}
215
217
216
218
private void SetupPSModulePath ( )
@@ -295,13 +297,15 @@ public PSObject FindModule(string moduleName)
295
297
{
296
298
return modulesFound [ moduleName ] ;
297
299
}
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
+ }
305
309
if ( modules == null )
306
310
{
307
311
return null ;
@@ -345,13 +349,15 @@ public void SaveModule(string moduleName)
345
349
{
346
350
return ;
347
351
}
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
+ }
355
361
}
356
362
357
363
/// <summary>
0 commit comments