@@ -64,19 +64,7 @@ public override void ExecuteCmdlet()
64
64
/// </summary>
65
65
private void GetByDefault ( )
66
66
{
67
- IEnumerable < CloudService > cloudServiceList = RecoveryServicesClient . GetCloudServices ( ) ;
68
-
69
- List < ASRVault > vaultList = new List < ASRVault > ( ) ;
70
- foreach ( var cloudService in cloudServiceList )
71
- {
72
- foreach ( var vault in cloudService . Resources )
73
- {
74
- if ( vault . Type . Equals ( Constants . ASRVaultType , StringComparison . InvariantCultureIgnoreCase ) )
75
- {
76
- vaultList . Add ( new ASRVault ( cloudService , vault ) ) ;
77
- }
78
- }
79
- }
67
+ List < ASRVault > vaultList = this . GetVaults ( ) ;
80
68
81
69
this . WriteVaults ( vaultList ) ;
82
70
}
@@ -88,6 +76,38 @@ private void GetByName()
88
76
{
89
77
bool vaultFound = false ;
90
78
79
+ List < ASRVault > vaultList = this . GetVaults ( out vaultFound ) ;
80
+
81
+ if ( ! vaultFound )
82
+ {
83
+ throw new InvalidOperationException (
84
+ string . Format (
85
+ Properties . Resources . VaultNotFound ,
86
+ this . Name ) ) ;
87
+ }
88
+
89
+ this . WriteVaults ( vaultList ) ;
90
+ }
91
+
92
+ /// <summary>
93
+ /// Overloaded GetVaults method so as to pass the out variable
94
+ /// </summary>
95
+ /// <returns>List of ASR Vaults</returns>
96
+ private List < ASRVault > GetVaults ( )
97
+ {
98
+ bool temp = false ;
99
+ return this . GetVaults ( out temp ) ;
100
+ }
101
+
102
+ /// <summary>
103
+ /// Gets the vaults in the cloud service.
104
+ /// </summary>
105
+ /// <param name="vaultFound">Out variable to indicate if the vault was found</param>
106
+ /// <returns>List of ASR Vaults</returns>
107
+ private List < ASRVault > GetVaults ( out bool vaultFound )
108
+ {
109
+ vaultFound = false ;
110
+
91
111
IEnumerable < CloudService > cloudServiceList = RecoveryServicesClient . GetCloudServices ( ) ;
92
112
93
113
List < ASRVault > vaultList = new List < ASRVault > ( ) ;
@@ -97,22 +117,23 @@ private void GetByName()
97
117
{
98
118
if ( vault . Type . Equals ( Constants . ASRVaultType , StringComparison . InvariantCultureIgnoreCase ) )
99
119
{
100
- if ( string . Compare ( this . Name , vault . Name , StringComparison . OrdinalIgnoreCase ) == 0 )
120
+ if ( string . Compare ( this . ParameterSetName , ASRParameterSets . ByName , StringComparison . OrdinalIgnoreCase ) == 0 )
121
+ {
122
+ if ( string . Compare ( this . Name , vault . Name , StringComparison . OrdinalIgnoreCase ) == 0 )
123
+ {
124
+ vaultFound = true ;
125
+ vaultList . Add ( new ASRVault ( cloudService , vault ) ) ;
126
+ }
127
+ }
128
+ else
101
129
{
102
- vaultFound = true ;
103
- this . WriteVault ( new ASRVault ( cloudService , vault ) ) ;
130
+ vaultList . Add ( new ASRVault ( cloudService , vault ) ) ;
104
131
}
105
132
}
106
133
}
107
134
}
108
135
109
- if ( ! vaultFound )
110
- {
111
- throw new InvalidOperationException (
112
- string . Format (
113
- Properties . Resources . VaultNotFound ,
114
- this . Name ) ) ;
115
- }
136
+ return vaultList ;
116
137
}
117
138
118
139
/// <summary>
0 commit comments