forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMshSnapinCommands.cs
More file actions
849 lines (745 loc) · 30 KB
/
Copy pathMshSnapinCommands.cs
File metadata and controls
849 lines (745 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
namespace Microsoft.PowerShell.Commands
{
#region PSSnapInCommandBase
/// <summary>
/// Base class for all the pssnapin related cmdlets.
/// </summary>
public abstract class PSSnapInCommandBase : PSCmdlet, IDisposable
{
#region IDisposable Members
/// <summary>
/// Set to true when object is disposed
/// </summary>
///
private bool _disposed;
/// <summary>
/// Dispose method unloads the app domain and the
/// resource reader if it was created.
/// </summary>
///
public void Dispose()
{
if (_disposed == false)
{
if (_resourceReader != null)
{
_resourceReader.Dispose();
_resourceReader = null;
}
GC.SuppressFinalize(this);
}
_disposed = true;
}
#endregion IDisposable Members
#region Cmdlet Methods
/// <summary>
/// Disposes the resource reader.
/// </summary>
///
protected override void EndProcessing()
{
if (_resourceReader != null)
{
_resourceReader.Dispose();
_resourceReader = null;
}
}
#endregion CmdletMethods
#region Internal Methods
/// <summary>
/// Runspace configuration for the current engine
/// </summary>
/// <remarks>
/// PSSnapIn cmdlets need <see cref="RunspaceConfigForSingleShell"/> object to work with.
/// </remarks>
internal RunspaceConfigForSingleShell Runspace
{
get
{
RunspaceConfigForSingleShell runSpace = Context.RunspaceConfiguration as RunspaceConfigForSingleShell;
if (runSpace == null)
{
return null;
}
return runSpace;
}
}
/// <summary>
/// Writes a non-terminating error onto the pipeline.
/// </summary>
/// <param name="targetObject">Object which caused this exception.</param>
/// <param name="errorId">ErrorId for this error.</param>
/// <param name="innerException">Complete exception object.</param>
/// <param name="category">ErrorCategory for this exception.</param>
internal void WriteNonTerminatingError(
Object targetObject,
string errorId,
Exception innerException,
ErrorCategory category)
{
WriteError(new ErrorRecord(innerException, errorId, category, targetObject));
}
/// <summary>
/// Searches the input list for the pattern supplied.
/// </summary>
/// <param name="searchList">Input list</param>
/// <param name="pattern">pattern with wildcards</param>
/// <returns>
/// A collection of string objects (representing PSSnapIn name)
/// that match the pattern.
/// </returns>
/// <remarks>
/// Please note that this method will use WildcardPattern class.
/// So it wont support all the 'regex' patterns
/// </remarks>
internal Collection<string>
SearchListForPattern(Collection<PSSnapInInfo> searchList,
string pattern)
{
Collection<string> listToReturn = new Collection<string>();
if (null == searchList)
{
// return an empty list
return listToReturn;
}
WildcardPattern matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase);
// We are doing WildCard search
foreach (PSSnapInInfo psSnapIn in searchList)
{
if (matcher.IsMatch(psSnapIn.Name))
{
listToReturn.Add(psSnapIn.Name);
}
}
// the returned list might contain 0 objects
return listToReturn;
}
/// <summary>
/// See if the snapin is already loaded..returns load snapin info if true, null otherwise.
/// </summary>
/// <returns></returns>
internal static PSSnapInInfo IsSnapInLoaded(Collection<PSSnapInInfo> loadedSnapins, PSSnapInInfo psSnapInInfo)
{
if (null == loadedSnapins)
{
return null;
}
foreach (PSSnapInInfo loadedPSSnapInInfo in loadedSnapins)
{
// See if the assembly-qualified names match and return the existing PSSnapInInfo
// if they do.
string loadedSnapInAssemblyName = loadedPSSnapInInfo.AssemblyName;
if (string.Equals(loadedPSSnapInInfo.Name, psSnapInInfo.Name, StringComparison.OrdinalIgnoreCase) &&
!string.IsNullOrEmpty(loadedSnapInAssemblyName)
&& string.Equals(loadedSnapInAssemblyName, psSnapInInfo.AssemblyName, System.StringComparison.OrdinalIgnoreCase))
{
return loadedPSSnapInInfo;
}
}
return null;
}
/// <summary>
/// Routine to get the list of loaded snapins...
/// </summary>
/// <returns></returns>
protected internal Collection<PSSnapInInfo> GetSnapIns(string pattern)
{
// If RunspaceConfiguration is not null, then return the list that it has
if (Runspace != null)
{
if (pattern != null)
return Runspace.ConsoleInfo.GetPSSnapIn(pattern, _shouldGetAll);
else
return Runspace.ConsoleInfo.PSSnapIns;
}
WildcardPattern matcher = null;
if (!String.IsNullOrEmpty(pattern))
{
bool doWildCardSearch = WildcardPattern.ContainsWildcardCharacters(pattern);
if (!doWildCardSearch)
{
// Verify PSSnapInID..
// This will throw if it not a valid name
PSSnapInInfo.VerifyPSSnapInFormatThrowIfError(pattern);
}
matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase);
}
Collection<PSSnapInInfo> snapins = new Collection<PSSnapInInfo>();
if (_shouldGetAll)
{
foreach (PSSnapInInfo snapinKey in PSSnapInReader.ReadAll())
{
if (matcher == null || matcher.IsMatch(snapinKey.Name))
snapins.Add(snapinKey);
}
}
else
{
// Otherwise, just scan through the list of cmdlets and rebuild the table.
List<CmdletInfo> cmdlets = InvokeCommand.GetCmdlets();
Dictionary<PSSnapInInfo, bool> snapinTable = new Dictionary<PSSnapInInfo, bool>();
foreach (CmdletInfo cmdlet in cmdlets)
{
PSSnapInInfo snapin = cmdlet.PSSnapIn;
if (snapin != null && !snapinTable.ContainsKey(snapin))
snapinTable.Add(snapin, true);
}
foreach (PSSnapInInfo snapinKey in snapinTable.Keys)
{
if (matcher == null || matcher.IsMatch(snapinKey.Name))
snapins.Add(snapinKey);
}
}
return snapins;
}
/// <summary>
/// Use to indicate if all registered snapins should be listed by GetSnapins...
/// </summary>
protected internal bool ShouldGetAll
{
get { return _shouldGetAll; }
set { _shouldGetAll = value; }
}
private bool _shouldGetAll;
/// <summary>
/// A single instance of the resource indirect reader. This is used to load the
/// managed resource assemblies in a different app-domain so that they can be unloaded.
/// For perf reasons we only want to create one instance for the duration of the command
/// and be sure it gets disposed when the command completes.
/// </summary>
///
internal RegistryStringResourceIndirect ResourceReader
{
get {
return _resourceReader ?? (_resourceReader = RegistryStringResourceIndirect.GetResourceIndirectReader());
}
}
private RegistryStringResourceIndirect _resourceReader;
#endregion
}
#endregion
#region Add-PSSnapIn
/// <summary>
/// Class that implements add-pssnapin cmdlet.
/// </summary>
[Cmdlet(VerbsCommon.Add, "PSSnapin", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113281")]
[OutputType(typeof(PSSnapInInfo))]
public sealed class AddPSSnapinCommand : PSSnapInCommandBase
{
#region Parameters
/// <summary>
/// Property that gets/sets PSSnapIn Ids for the cmdlet.
/// </summary>
/// <value>An array of strings representing PSSnapIn ids.</value>
[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
public string[] Name
{
get
{
return _pssnapins;
}
set
{
_pssnapins = value;
}
}
private string[] _pssnapins;
/// <summary>
/// Gets or sets the Passthru flag for the operation.
/// If true, the PSSnapInInfo object is passed down the
/// output pipeline.
/// </summary>
[Parameter()]
public SwitchParameter PassThru
{
get
{
return _passThru;
}
set
{
_passThru = value;
}
}
private bool _passThru;
#endregion
#region Overrides
/// <summary>
/// Adds pssnapins to console file and loads the pssnapin dlls into
/// the current monad runtime.
/// </summary>
/// <remarks>
/// The new pssnapin information is not stored in the console file until
/// the file is saved.
/// </remarks>
protected override void ProcessRecord()
{
// Cache for the information stored in the registry
// update the cache the first time a wildcard is found..
Collection<PSSnapInInfo> listToSearch = null;
foreach (string pattern in _pssnapins)
{
Exception exception = null;
Collection<string> listToAdd = new Collection<string>();
try
{
// check whether there are any wildcard characters
bool doWildCardSearch = WildcardPattern.ContainsWildcardCharacters(pattern);
if (doWildCardSearch)
{
// wildcard found in the pattern
// Get all the possible candidates for current monad version
if (listToSearch == null)
{
// cache snapin registry information...
// For 3.0 PowerShell, we still use "1" as the registry version key for
// Snapin and Custom shell lookup/discovery.
// For 3.0 PowerShell, we use "3" as the registry version key only for Engine
// related data like ApplicationBase etc.
listToSearch = PSSnapInReader.ReadAll(PSVersionInfo.RegistryVersion1Key);
}
listToAdd = SearchListForPattern(listToSearch, pattern);
// listToAdd wont be null..
Diagnostics.Assert(listToAdd != null, "Pattern matching returned null");
if (listToAdd.Count == 0)
{
if (_passThru)
{
// passThru is specified and we have nothing to add...
WriteNonTerminatingError(pattern, "NoPSSnapInsFound",
PSTraceSource.NewArgumentException(pattern,
MshSnapInCmdletResources.NoPSSnapInsFound, pattern),
ErrorCategory.InvalidArgument);
}
continue;
}
}
else
{
listToAdd.Add(pattern);
}
// now add all the snapins for this pattern...
AddPSSnapIns(listToAdd);
}
catch (PSArgumentException ae)
{
exception = ae;
}
catch (System.Security.SecurityException se)
{
exception = se;
}
if (exception != null)
{
WriteNonTerminatingError(pattern,
"AddPSSnapInRead",
exception,
ErrorCategory.InvalidArgument);
}
}
}
#endregion
#region Private Methods
/// <summary>
/// Adds one or more snapins
/// </summary>
/// <param name="snapInList">List of snapin IDs</param>
/// <remarks>
/// This is a helper method and should not throw any
/// exceptions. All exceptions are caught and displayed
/// to the user using write* methods
/// </remarks>
private void AddPSSnapIns(Collection<string> snapInList)
{
if (snapInList == null)
{
// nothing to add
return;
}
//BUGBUG TODO - brucepay - this is a workaround for not being able to dynamically update
// the set of cmdlets in a runspace if there is no RunspaceConfiguration object.
// This is a temporary fix to unblock remoting tests and need to be corrected/completed
// before we can ship...
// If there is no RunspaceConfig object, then
// use an InitialSessionState object to gather and
// bind the cmdlets from the snapins...
if (Context.RunspaceConfiguration == null)
{
Collection<PSSnapInInfo> loadedSnapins = base.GetSnapIns(null);
InitialSessionState iss = InitialSessionState.Create();
bool isAtleastOneSnapinLoaded = false;
foreach (string snapIn in snapInList)
{
if (InitialSessionState.IsEngineModule(snapIn))
{
WriteNonTerminatingError(snapIn, "LoadSystemSnapinAsModule",
PSTraceSource.NewArgumentException(snapIn,
MshSnapInCmdletResources.LoadSystemSnapinAsModule, snapIn),
ErrorCategory.InvalidArgument);
}
else
{
PSSnapInException warning;
try
{
// Read snapin data
PSSnapInInfo newPSSnapIn = PSSnapInReader.Read(Utils.GetCurrentMajorVersion(), snapIn);
PSSnapInInfo psSnapInInfo = IsSnapInLoaded(loadedSnapins, newPSSnapIn);
// that means snapin is not already loaded ..so load the snapin
// now.
if (null == psSnapInInfo)
{
psSnapInInfo = iss.ImportPSSnapIn(snapIn, out warning);
isAtleastOneSnapinLoaded = true;
Context.InitialSessionState.ImportedSnapins.Add(psSnapInInfo.Name, psSnapInInfo);
}
// Write psSnapInInfo object only if passthru is specified.
if (_passThru)
{
// Load the pssnapin info properties that are localizable and redirected in the registry
psSnapInInfo.LoadIndirectResources(ResourceReader);
WriteObject(psSnapInInfo);
}
}
catch (PSSnapInException pse)
{
WriteNonTerminatingError(snapIn, "AddPSSnapInRead", pse, ErrorCategory.InvalidData);
}
}
}
if (isAtleastOneSnapinLoaded)
{
// Now update the session state with the new stuff...
iss.Bind(Context, /*updateOnly*/ true);
}
return;
}
foreach (string psSnapIn in snapInList)
{
Exception exception = null;
try
{
PSSnapInException warning = null;
PSSnapInInfo psSnapInInfo = this.Runspace.AddPSSnapIn(psSnapIn, out warning);
if (warning != null)
{
WriteNonTerminatingError(psSnapIn, "AddPSSnapInRead", warning, ErrorCategory.InvalidData);
}
// Write psSnapInInfo object only if passthru is specified.
if (_passThru)
{
// Load the pssnapin info properties that are localizable and redirected in the registry
psSnapInInfo.LoadIndirectResources(ResourceReader);
WriteObject(psSnapInInfo);
}
}
catch (PSArgumentException ae)
{
exception = ae;
}
catch (PSSnapInException sle)
{
exception = sle;
}
catch (System.Security.SecurityException se)
{
exception = se;
}
if (exception != null)
{
WriteNonTerminatingError(psSnapIn,
"AddPSSnapInRead",
exception,
ErrorCategory.InvalidArgument);
}
}
}
#endregion
}
#endregion
#region Remove-PSSnapIn
/// <summary>
/// Class that implements remove-pssnapin cmdlet.
/// </summary>
[Cmdlet(VerbsCommon.Remove, "PSSnapin", SupportsShouldProcess = true, HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113378")]
[OutputType(typeof(PSSnapInInfo))]
public sealed class RemovePSSnapinCommand : PSSnapInCommandBase
{
#region Parameters
/// <summary>
/// Property that gets/sets PSSnapIn Ids for the cmdlet.
/// </summary>
/// <value>An array of strings representing PSSnapIn ids.</value>
[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
public string[] Name
{
get
{
return _pssnapins;
}
set
{
_pssnapins = value;
}
}
private string[] _pssnapins;
/// <summary>
/// Gets or sets the Passthru flag for the operation.
/// If true, the PSSnapInInfo object is also passed
/// down the output pipeline.
/// </summary>
[Parameter()]
public SwitchParameter PassThru
{
get
{
return _passThru;
}
set
{
_passThru = value;
}
}
private bool _passThru;
#endregion
#region Overrides
/// <summary>
/// Removes pssnapins from the current console file.
/// </summary>
/// <remarks>
/// The pssnapin is not unloaded from the current engine. So all the cmdlets that are
/// represented by this pssnapin will continue to work.
/// </remarks>
protected override void ProcessRecord()
{
foreach (string psSnapIn in _pssnapins)
{
Collection<PSSnapInInfo> snapIns = GetSnapIns(psSnapIn);
// snapIns won't be null..
Diagnostics.Assert(snapIns != null, "GetSnapIns() returned null");
if (snapIns.Count == 0)
{
WriteNonTerminatingError(psSnapIn, "NoPSSnapInsFound",
PSTraceSource.NewArgumentException(psSnapIn,
MshSnapInCmdletResources.NoPSSnapInsFound, psSnapIn),
ErrorCategory.InvalidArgument);
continue;
}
foreach (PSSnapInInfo snapIn in snapIns)
{
// confirm the operation first
// this is always false if WhatIf is set
if (ShouldProcess(snapIn.Name))
{
Exception exception = null;
if (this.Runspace == null && this.Context.InitialSessionState != null)
{
try
{
// Check if this snapin can be removed
// Monad has specific restrictions on the mshsnapinid like
// mshsnapinid should be A-Za-z0-9.-_ etc.
PSSnapInInfo.VerifyPSSnapInFormatThrowIfError(snapIn.Name);
if (MshConsoleInfo.IsDefaultPSSnapIn(snapIn.Name, this.Context.InitialSessionState.defaultSnapins))
{
throw PSTraceSource.NewArgumentException(snapIn.Name, ConsoleInfoErrorStrings.CannotRemoveDefault, snapIn.Name);
}
// Handle the initial session state case...
InitialSessionState iss = InitialSessionState.Create();
PSSnapInException warning;
// Get the snapin information...
iss.ImportPSSnapIn(snapIn, out warning);
iss.Unbind(Context);
Context.InitialSessionState.ImportedSnapins.Remove(snapIn.Name);
}
catch (PSArgumentException ae)
{
exception = ae;
}
if (exception != null)
{
WriteNonTerminatingError(psSnapIn, "RemovePSSnapIn", exception, ErrorCategory.InvalidArgument);
}
}
else
{
try
{
PSSnapInException warning = null;
PSSnapInInfo psSnapInInfo = this.Runspace.RemovePSSnapIn(snapIn.Name, out warning);
if (warning != null)
{
WriteNonTerminatingError(snapIn.Name, "RemovePSSnapInRead", warning, ErrorCategory.InvalidData);
}
if (_passThru)
{
// Load the pssnapin info properties that are localizable and redirected in the registry
psSnapInInfo.LoadIndirectResources(ResourceReader);
WriteObject(psSnapInInfo);
}
}
catch (PSArgumentException ae)
{
exception = ae;
}
if (exception != null)
{
WriteNonTerminatingError(psSnapIn, "RemovePSSnapIn", exception, ErrorCategory.InvalidArgument);
}
}
} // ShouldContinue
}
}
}
#endregion
}
#endregion
#region Get-PSSnapIn
/// <summary>
/// Class that implements get-pssnapin cmdlet.
/// </summary>
[Cmdlet(VerbsCommon.Get, "PSSnapin", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113330")]
[OutputType(typeof(PSSnapInInfo))]
public sealed class GetPSSnapinCommand : PSSnapInCommandBase
{
#region Parameters
/// <summary>
/// Name(s) of PSSnapIn(s).
/// </summary>
[Parameter(Position = 0, Mandatory = false)]
public string[] Name
{
get
{
return _pssnapins;
}
set
{
_pssnapins = value;
}
}
private string[] _pssnapins;
/// <summary>
/// Property that determines whether to get all pssnapins that are currently
/// registered ( in registry ).
/// </summary>
/// <value>
/// A boolean that determines whether to get all pssnapins that are currently
/// registered ( in registry ).
/// </value>
[Parameter(Mandatory = false)]
public SwitchParameter Registered
{
get
{
return ShouldGetAll;
}
set
{
ShouldGetAll = value;
}
}
#endregion
#region Overrides
/// <summary>
/// Constructs PSSnapInfo objects as requested by the user and writes them to the
/// output buffer.
/// </summary>
protected override void BeginProcessing()
{
if (_pssnapins != null)
{
foreach (string psSnapIn in _pssnapins)
{
Exception exception = null;
try
{
Collection<PSSnapInInfo> psSnapInInfoList = GetSnapIns(psSnapIn);
// psSnapInInfoList wont be null..
Diagnostics.Assert(psSnapInInfoList != null, "ConsoleInfo.GetPSSnapIn returned null");
if (psSnapInInfoList.Count == 0)
{
WriteNonTerminatingError(psSnapIn, "NoPSSnapInsFound",
PSTraceSource.NewArgumentException(psSnapIn,
MshSnapInCmdletResources.NoPSSnapInsFound, psSnapIn),
ErrorCategory.InvalidArgument);
continue;
}
foreach (PSSnapInInfo pssnapinInfo in psSnapInInfoList)
{
// Load the pssnapin info properties that are localizable and redirected in the registry
pssnapinInfo.LoadIndirectResources(ResourceReader);
WriteObject(pssnapinInfo);
}
}
catch (System.Security.SecurityException se)
{
exception = se;
}
catch (PSArgumentException ae)
{
exception = ae;
}
if (exception != null)
{
WriteNonTerminatingError(psSnapIn, "GetPSSnapInRead", exception, ErrorCategory.InvalidArgument);
}
}
}
else if (ShouldGetAll)
{
Exception exception = null;
try
{
Collection<PSSnapInInfo> psSnapInInfoList = PSSnapInReader.ReadAll();
foreach (PSSnapInInfo pssnapinInfo in psSnapInInfoList)
{
// Load the pssnapin info properties that are localizable and redirected in the registry
pssnapinInfo.LoadIndirectResources(ResourceReader);
WriteObject(pssnapinInfo);
}
}
catch (System.Security.SecurityException se)
{
exception = se;
}
catch (PSArgumentException ae)
{
exception = ae;
}
if (exception != null)
{
WriteNonTerminatingError(this, "GetPSSnapInRead", exception, ErrorCategory.InvalidArgument);
}
}
else
{
// this should never throw..
Collection<PSSnapInInfo> psSnapInInfoList = GetSnapIns(null);
foreach (PSSnapInInfo pssnapinInfo in psSnapInInfoList)
{
// Load the pssnapin info properties that are localizable and redirected in the registry
pssnapinInfo.LoadIndirectResources(ResourceReader);
WriteObject(pssnapinInfo);
}
}
}
#endregion
}
#endregion
}