@@ -131,103 +131,103 @@ else
131131 $ResourceGroupName = $DS_ResourceGroupName
132132}
133133
134- foreach ($ResourceGroup in $ResourceGroupName )
134+ foreach ($ResourceGroup in $ResourceGroupName )
135+ {
136+ if ($DS_ServerName -eq " " )
137+ {
138+ $ServerName = Get-AzureRmSqlServer - ResourceGroupName $ResourceGroup | select - ExpandProperty ServerName
139+ }
140+ else
141+ {
142+ $ServerName = $DS_ServerName
143+ }
144+
145+ foreach ($Server in $ServerName )
135146 {
136- if ($DS_ServerName -eq " " )
147+ if ($DS_DatabaseName -eq " " )
137148 {
138- $ServerName = Get-AzureRmSqlServer - ResourceGroupName $ResourceGroup | select - ExpandProperty ServerName
149+ $DatabaseName = Get-AzureRmSqlDatabase - ResourceGroupName $ResourceGroup - ServerName $Server | select - ExpandProperty DatabaseName
139150 }
140151 else
141152 {
142- $ServerName = $DS_ServerName
153+ $DatabaseName = $DS_DatabaseName
143154 }
144155
145- foreach ($Server in $ServerName )
156+ foreach ($Database in $DatabaseName )
146157 {
147- if ($DS_DatabaseName -eq " " )
158+ if ($Database -eq " master " )
148159 {
149- $DatabaseName = Get-AzureRmSqlDatabase - ResourceGroupName $ResourceGroup - ServerName $Server | select - ExpandProperty DatabaseName
160+ continue ;
161+ }
162+
163+ if ($DS_SyncGroupName -eq " " )
164+ {
165+ $SyncGroupName = Get-AzureRmSqlSyncGroup - ResourceGroupName $ResourceGroup - ServerName $Server - DatabaseName $Database | select - ExpandProperty SyncGroupName
150166 }
151167 else
152168 {
153- $DatabaseName = $DS_DatabaseName
169+ $SyncGroupName = $DS_SyncGroupName
154170 }
155171
156- foreach ($Database in $DatabaseName )
172+ foreach ($SyncGroup in $SyncGroupName )
157173 {
158- if ($Database -eq " master" )
159- {
160- continue ;
161- }
162-
163- if ($DS_SyncGroupName -eq " " )
164- {
165- $SyncGroupName = Get-AzureRmSqlSyncGroup - ResourceGroupName $ResourceGroup - ServerName $Server - DatabaseName $Database | select - ExpandProperty SyncGroupName
166- }
167- else
174+ $Logs = Get-AzureRmSqlSyncGroupLog - ResourceGroupName $ResourceGroup `
175+ - ServerName $Server `
176+ - DatabaseName $Database `
177+ - SyncGroupName $SyncGroup `
178+ - starttime $StartTime `
179+ - endtime $EndTime ;
180+
181+ if ($Logs.Length -gt 0 )
168182 {
169- $SyncGroupName = $DS_SyncGroupName
170- }
171-
172- foreach ($SyncGroup in $SyncGroupName )
183+ foreach ($Log in $Logs )
173184 {
174- $Logs = Get-AzureRmSqlSyncGroupLog - ResourceGroupName $ResourceGroup `
175- - ServerName $Server `
176- - DatabaseName $Database `
177- - SyncGroupName $SyncGroup `
178- - starttime $StartTime `
179- - endtime $EndTime ;
180-
181- if ($Logs.Length -gt 0 )
182- {
183- foreach ($Log in $Logs )
184- {
185- $Log | Add-Member - Name " SubscriptionId" - Value $SubscriptionId - MemberType NoteProperty
186- $Log | Add-Member - Name " ResourceGroupName" - Value $ResourceGroup - MemberType NoteProperty
187- $Log | Add-Member - Name " ServerName" - Value $Server - MemberType NoteProperty
188- $Log | Add-Member - Name " HubDatabaseName" - Value $Database - MemberType NoteProperty
189- $Log | Add-Member - Name " SyncGroupName" - Value $SyncGroup - MemberType NoteProperty
185+ $Log | Add-Member - Name " SubscriptionId" - Value $SubscriptionId - MemberType NoteProperty
186+ $Log | Add-Member - Name " ResourceGroupName" - Value $ResourceGroup - MemberType NoteProperty
187+ $Log | Add-Member - Name " ServerName" - Value $Server - MemberType NoteProperty
188+ $Log | Add-Member - Name " HubDatabaseName" - Value $Database - MemberType NoteProperty
189+ $Log | Add-Member - Name " SyncGroupName" - Value $SyncGroup - MemberType NoteProperty
190190
191- # Filter out Successes to Reduce Data Volume to OMS
192- # Include the 5 commented out line below to enable the filter
193- # For($i=0; $i -lt $Log.Length; $i++ ) {
194- # if($Log[$i].LogLevel -eq "Success") {
195- # $Log[$i] =""
196- # }
197- # }
191+ # Filter out Successes to Reduce Data Volume to OMS
192+ # Include the 5 commented out line below to enable the filter
193+ # For($i=0; $i -lt $Log.Length; $i++ ) {
194+ # if($Log[$i].LogLevel -eq "Success") {
195+ # $Log[$i] =""
196+ # }
197+ # }
198198
199199
200200
201- }
201+ }
202202
203203
204- $json = ConvertTo-JSON $logs
204+ $json = ConvertTo-JSON $logs
205205
206206
207207
208- Post- OMSData - customerId $customerId - sharedKey $sharedKey - body ([System.Text.Encoding ]::UTF8.GetBytes($json )) - logType $logType
209- if ($result -eq 200 )
210- {
211- Write-Host " Success"
212- }
213- if ($result -ne 200 )
214- {
215- throw
208+ Post- OMSData - customerId $customerId - sharedKey $sharedKey - body ([System.Text.Encoding ]::UTF8.GetBytes($json )) - logType $logType
209+ if ($result -eq 200 )
210+ {
211+ Write-Host " Success"
212+ }
213+ if ($result -ne 200 )
214+ {
215+ throw
216216@"
217- Posting to OMS Failed
218- Runbook Name: DataSyncOMSIntegration
217+ Posting to OMS Failed
218+ Runbook Name: DataSyncOMSIntegration
219219"@
220- }
221- }
220+ }
222221 }
223222 }
224223 }
225224 }
225+ }
226226
227227
228228
229- Set-AzureRmAutomationVariable - ResourceGroupName $AC_ResourceGroupName `
230- –AutomationAccountName $AC_AccountName `
231- - Name $AC_LastUpdatedTimeVariableName `
232- - Value $EndTime `
233- - Encrypted $False
229+ Set-AzureRmAutomationVariable - ResourceGroupName $AC_ResourceGroupName `
230+ –AutomationAccountName $AC_AccountName `
231+ - Name $AC_LastUpdatedTimeVariableName `
232+ - Value $EndTime `
233+ - Encrypted $False
0 commit comments