VConnectMultiStampManagement.psm1

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
Invoke-InstallOrUpdateModule 'SqlServer'

function Get-VConnectAzsStampsHealth {
      [CmdletBinding()]
      param (
            [Parameter(Mandatory = $true, Position = 0, HelpMessage = "VConnect API connection name; Please use Add-ApiConnection to create new connecition")]
            [string] $endpointName,
            [Switch] $exportCsv,
            [Switch] $gridView,
            [Switch] $printToConsole,
            [Switch] $extendedOutput,
            [Switch] $showLogs
      )
      try {
            $result = Invoke-RestApiRequest -endpointName $endpointName -relativeUrl 'admin/AzureStackAdminConnections/Get' -method 'GET'

            if (($result.Length -eq 2) -and ($null -ne $result[1])) {

                  $azsConnectionsList = $result[1] | Select-Object -Property ConnectionId, ConnectionName, Location, ArmEndpointUrl, TenantArmEndpointUrl, DefaultProviderSubscriptionId, TenantId, ClientId, LoginEndpoint, UseCertificateThumbprintInsteadAppSecret, EnvironmentCategoryTag, EnvironmentSubCategoryTag, IsAdfs, IsDisconnectedEnvironment, IsAllowManagement, CreatedTime, LastUpdatedTime

                  foreach ($azsConnection in $azsConnectionsList) {
                        try {
                              $adminArmEndpoint = $azsConnection.ArmEndpointUrl
                              $requestUrl = "$($adminArmEndpoint)/metadata/endpoints?api-version=2015-01-11"
                              if ($showLogs) {
                                    Write-Host "$($azsConnection.ConnectionName): Validating ARM endpoint..."
                                    Invoke-WebRequest $requestUrl
                              } else {
                                    Invoke-WebRequest $requestUrl |  Out-Null
                              }
                              Add-Member -InputObject $azsConnection -MemberType NoteProperty -Name Reachable -Value $true
                        }
                        catch {
                              $exception = $_
                              if ($showLogs) {
                                    Write-Host "$($azsConnection.ConnectionName) Validating ARM endpoint failed."
                                    Write-Host $exception
                              }
                              Add-Member -InputObject $azsConnection -MemberType NoteProperty -Name Reachable -Value $false
                        }
                  }

                  if ($gridView) {
                        $azsConnectionsList | Out-GridView
                        return
                  } 
                  if ($exportCsv) {
                        $dateTimeTicks = (Get-Date).Ticks
                        $outFileName = "Get-MamStamps-$($endpointName)-$($dateTimeTicks).csv"
                        Write-Host "Writing to File: $($outFileName)"
                        $azsConnectionsList | Export-Csv -Path $outFileName -NoTypeInformation
                        return
                  }
                  if ($printToConsole) {
                        if (-not $extendedOutput) {
                              $azsConnectionsList = $azsConnectionsList | Select-Object -Property ConnectionId, ConnectionName, Location, IsAdfs, EnvironmentCategoryTag, ArmEndpointUrl,TenantArmEndpointUrl,Reachable
                        }
                        Write-Host ""
                        Write-Host "Azure Stack Hub Stamp Connectivity Status" -BackgroundColor White -ForegroundColor DarkBlue
                        Write-Host ""

                        foreach ($azsConnection in $azsConnectionsList) {
                              Write-Host "------------------------------------------------------------------------------------------------"
                              if ($azsConnection.Reachable) {
                                    Write-Host "$($azsConnection.ConnectionName) is Reachable" -BackgroundColor Green -ForegroundColor Black
                              }
                              else {
                                    Write-Host "$($azsConnection.ConnectionName) is not Reachable" -BackgroundColor Red -ForegroundColor Black
                              }
                              Write-Host "------------------------------------------------------------------------------------------------"
                              Write-Output -InputObject $azsConnection
                              Write-Host ""
                        }
                        return
                  }
                  return $azsConnectionsList
            }
            Write-Error "Command returns null result."
            return $null
      }
      catch {
            $exception = $_
            Write-Host "Azure Stack Hub Stamp ARM endpoint validation: Failed to get stamp details."
            Write-Error $exception
      }
}

function Get-VConnectDiscoveredResourcesStatus {
      param(
            [Parameter(Mandatory = $true, Position = 0)]
            $name,
            [Parameter(Mandatory = $true, Position = 1)]
            $dbName,
            [Parameter(Mandatory = $false, Position = 2)]
            [int] $connectionId = 0,
            [Switch] $printToConsole
            )

      $query = "select
           drs.PlatformConnectionId as ConnectionId,
           drs.Cluster as StampName,
           drs.PlatformServiceName as Service,
           drs.ResourceSubType as ResourceType,
           Max(drs.DiscoveredDate) as UpdatesDate,
           Max(dj.Id) as DiscoverJobId,
           Max(ds.DeploymentId) as DeploymentId,
           Max(ops.ResultMessage) as LastMessage
           from DiscoveredResources drs with (nolock)
           inner join DiscoveryJobs dj with (nolock) on drs.DiscoveryJobId = dj.Id
           inner join Deployments ds with (nolock) on ds.DeploymentId = dj.DiscoveryJobDeploymentId
           inner join Operations ops with (nolock) on ops.DeploymentId = ds.DeploymentId
           Where ($connectionId <= 0 or drs.PlatformConnectionId = $connectionId)
              and drs.IsDeleted = 0
              and drs.PlatformConnectionType = 1050
              and ds.StatusString = 'Completed'
              and ops.OperationName = 'DiscoverAdminPlatformServiceOp'
           Group by PlatformConnectionId, Cluster, PlatformServiceName, ResourceSubType
           order by Cluster, PlatformServiceName, ResourceSubType"


      Write-Host "Azure Stack Hub Stamp Resource Update Status..."

      if ($printToConsole) {
        Invoke-SqlDbQuery $name $query $dbName -printToConsole
        return
      }
      return Invoke-SqlDbQuery $name $query $dbName
}
# SIG # Begin signature block
# MIIOCwYJKoZIhvcNAQcCoIIN/DCCDfgCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUC3NouP/DyloolTJ6ukJj7yjt
# gAGgggtCMIIFWjCCBEKgAwIBAgIQDO0lEK+T1uQiVg3lGt++5DANBgkqhkiG9w0B
# AQsFADB9MQswCQYDVQQG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