-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSfBLISMigrationTools
309 lines (257 loc) · 11 KB
/
SfBLISMigrationTools
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
Function Copy-SfBLISSubnetsToTeams {
<#
.SYNOPSIS
Copies an on-prem Skype for Business LIS location and subnet database to Teams
.DESCRIPTION
Copies an on-prem Skype for Business LIS location and subnet database to Teams.
.PARAMETER Subnet
The Dubnet to copy from the on-prem SfB LIS database
.PARAMETER Description
The Description to copy from the on-prem SfB LIS database
.PARAMETER Location
The Location to copy from the on-prem SfB LIS database
.PARAMETER Description
The Description to copy from the on-prem SfB LIS database
.PARAMETER HouseNumber
The HouseNumber to copy from the on-prem SfB LIS database
.PARAMETER HouseNumberSuffix
The HouseNumberSuffix to copy from the on-prem SfB LIS database
.PARAMETER PreDirectional
The PreDirectional to copy from the on-prem SfB LIS database
.PARAMETER StreetName
The StreetName to copy from the on-prem SfB LIS database
.PARAMETER PostDirectional
The PostDirectional to copy from the on-prem SfB LIS database
.PARAMETER City
The City to copy from the on-prem SfB LIS database
.PARAMETER State
The State to copy from the on-prem SfB LIS database
.PARAMETER PostalCode
The PostalCode to copy from the on-prem SfB LIS database
.PARAMETER Country
The Country to copy from the on-prem SfB LIS database
.PARAMETER SkipGeoLocate
Don't attempt to performe a geo-locate on the location
.EXAMPLE
Get-CsLisSubnet | Copy-SfBLISSubnetsToTeams
Copies all Skype for Business LIS subnets and associated locations/civic addresses directly from SfB
.EXAMPLE
Import-Csv LISSubnets.csv | Copy-SfBLISSubnetsToTeams
Copies all Skype for Business LIS subnets and associated locations/civic addresses from a CSV export
from SfB via the Get-CsLisSubnet command
.NOTES
Version 1.10
Build: Oct 28, 2020
Copyright © 2020 Ken Lasko
https://www.ucdialplans.com
#>
Param (
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$Subnet,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$Description,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$Location,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$CompanyName,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$HouseNumber,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$HouseNumberSuffix,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$PreDirectional,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$StreetName,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$PostDirectional,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$City,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$State,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[string]$PostalCode,
[Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
[Alias("Country")]
[string]$CountryOrRegion,
[parameter(Mandatory=$False)]
[switch]$SkipGeoLocate,
[parameter(Mandatory=$False)]
[string]$OverrideAdminDomain
)
Begin {
If ((Get-PSSession | Where-Object -FilterScript {
$_.ComputerName -eq 'api.interfaces.records.teams.microsoft.com' -Or $_.ComputerName -like '*.online.lync.com'
}).State -eq 'Opened') {
Write-Host -Object 'Using existing session credentials'
}
Else {
Write-Host -Object 'Logging into Office 365...'
If ($OverrideAdminDomain) {
$O365Session = (New-CsOnlineSession -OverrideAdminDomain $OverrideAdminDomain)
}
Else {
$O365Session = (New-CsOnlineSession)
}
$null = (Import-PSSession -Session $O365Session -AllowClobber)
}
}
Process {
#Check for existing location in online LIS database
Write-Host "Working on $($Subnet) in $($Location)"
$ExistingAddresses = @()
$ExistingAddresses += Get-CsOnlineLisCivicAddress -City $City -CountryorRegion $CountryOrRegion
$Item = $PSItem
Switch ($ExistingAddresses.Count) {
0 {
#Convert to hashtable
$Hash = @{}
$Item | Get-Member -MemberType *Property | % { If ($Item.($_.name) -ne '') {$Hash.($_.name) = $Item.($_.name)} }
#Remove invalid from hash to prevent issues with creating new civic address/location
$Hash.Remove('Subnet')
$Hash.Remove('Description')
#Get lat/long
If (!$SkipGeoLocate) {
$LatLong = Get-LatLong "$($HouseNumber) $($StreetName) $($StreetSuffix) $($City) $($State) $($CountryOrRegion)"
$Hash.Add('Latitude', $LatLong.Latitude)
$Hash.Add('Longitude', $LatLong.Longitude)
}
#Remove fields that aren't needed for civic address
$Hash.Remove('Location')
# Create civic address
Write-Host "Creating civic address for $($Location) $($City)"
$NewCivic = New-CsOnlineLisCivicAddress @Hash
Write-Host "Creating default location for $($Location) $($City)"
$NewLoc = New-CsOnlineLisLocation -Location $Location -CivicAddressId $NewCivic.CivicAddressId
# Assign subnet to location
Write-Host "Assigning $($Subnet) to $($Location)"
Set-CsOnlineLISSubnet -Subnet $Subnet -Description $Description -LocationID $NewLoc.LocationID
Break
}
1 {
Write-Host "One match found for address $($HouseNumber) $($StreetName) $($StreetSuffix) $($City) $($State) $($CountryOrRegion)"
# Check for existing location at given civic address/location
$ExistingLocation = Get-CsOnlineLisLocation -CivicAddressId $ExistingAddresses.CivicAddressId | Where {$_.Location -eq $Location}
If ($ExistingLocation) {
Write-Host "Assigning $($Subnet) to $($Location)"
Set-CsOnlineLISSubnet -Subnet $Subnet -Description $Description -LocationID $ExistingLocation.LocationID
}
Else {
Write-Host "Creating new $($Location) location for $($City)"
$NewLoc = New-CsOnlineLisLocation -Location $Location -CivicAddressId $ExistingAddresses.CivicAddressId
# Assign subnet to location
Write-Host "Assigning $($Subnet) to $($Location)"
Set-CsOnlineLISSubnet -Subnet $Subnet -Description $Description -LocationID $NewLoc.LocationID
}
Break
}
Default {
Write-Host "Multiple matches found for address in $($City) $($CountryOrRegion)"
$MatchFound = $FALSE
ForEach ($Addr in $ExistingAddresses) {
If ($Addr.HouseNumber -eq $HouseNumber -And
$Addr.StreetName -eq $StreetName -And
$Addr.State -eq $StateorProvince -And
$Addr.PostalCode -eq $PostalCode) {
$MatchFound = $TRUE
Write-Host "Match found for address $($HouseNumber) $($StreetName) $($StreetSuffix) $($City) $($State) $($CountryOrRegion)"
# Check for existing location at given civic address/location
$ExistingLocation = Get-CsOnlineLisLocation -CivicAddressId $Addr.CivicAddressId | Where {$_.Location -eq $Location}
If ($ExistingLocation) {
Write-Host "Assigning $($Subnet) to $($Location)"
Set-CsOnlineLISSubnet -Subnet $Subnet -Description $Description -LocationID $ExistingLocation.LocationID
}
Else {
Write-Host "Creating new $($Location) location for $($City)"
$NewLoc = New-CsOnlineLisLocation -Location $Location -CivicAddressId $Addr.CivicAddressId
# Assign subnet to location
Write-Host "Assigning $($Subnet) to $($Location)"
Set-CsOnlineLISSubnet -Subnet $Subnet -Description $Description -LocationID $NewLoc.LocationID
}
Break
}
}
If (!$MatchFound) {
Write-Host "No match found for address $($HouseNumber) $($StreetName) $($StreetSuffix) $($City) $($State) $($CountryOrRegion)"
#Remove empty elements
$psobject.Properties | Where-Object -FilterScript { -not $_.value } | ForEach-Object -Process { $psobject.Properties.Remove($_.name) }
#Convert to hashtable
$Hash = @{}
$psobject.properties | Foreach { $Hash[$_.Name] = $_.Value }
#Remove invalid from hash to prevent issues with creating new civic address/location
$Hash.Remove("Subnet")
$Hash.Remove("Description")
#Get lat/long
$LatLong = Get-LatLong "$($HouseNumber) $($StreetName) $($StreetSuffix) $($City) $($State) $($CountryOrRegion)"
$Hash.Add('Latitude', $LatLong.Latitude)
$Hash.Add('Longitude', $LatLong.Longitude)
# Create civic address/location
Write-Host "Creating location/civic address for $($Location) $($City)"
$NewLoc = New-CsOnlineLisLocation @Hash
# Assign subnet to location
Write-Host "Assigning $($Subnet) to $($Location)"
Set-CsOnlineLISSubnet -Subnet $Subnet -Description $Description -LocationID $NewLoc.LocationID
}
}
}
}
}
Function Get-LatLong {
<#
.SYNOPSIS
Returns the geographical coordinates for an address.
.DESCRIPTION
Returns the geographical coordinates for an address.
.PARAMETER Address
The address of the location to return information on. Include as much detail as possible.
.EXAMPLE
Get-LatLong -Address "33 Main Street, Jonestown, NY, USA"
Retrieves the latitude/longitude for the selected location
.NOTES
Version 1.0
Build: Oct 18, 2020
Copyright © 2020 Ken Lasko
https://www.ucdialplans.com
#>
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[String]$Address
)
Begin {
$GoogleGeoAPIKey = [System.Environment]::GetEnvironmentVariable('GoogleGeocode_API_Key','user')
If(!$GoogleGeoAPIKey) {
Write-Host -ForegroundColor Red "You need to register for an API key and save it as persistent environment variable called GoogleGeocode_API_Key on this machine. Follow this link to get an API Key - http://developers.google.com/maps/documentation/geocoding/get-api-key "
$GoogleGeoAPIKey = Read-Host "Enter a valid Google API key to be saved as environment variable GoogleGeocode_API_Key"
[System.Environment]::SetEnvironmentVariable('GoogleGeocode_API_Key', $GoogleGeoAPIKey,[System.EnvironmentVariableTarget]::User)
}
}
Process {
Try {
$JSON = Invoke-RestMethod -Method GET -Uri "https://maps.googleapis.com/maps/api/geocode/json?address=$Address&key=$GoogleGeoAPIKey" -ErrorVariable EV
$Status = $JSON.Status
[double]$Lat = $JSON.results.geometry.location.lat
[double]$Lng = $JSON.results.geometry.location.lng
$LatLong = New-Object PSObject
If($Status -eq "OK") {
$LatLong | Add-Member -type NoteProperty -Name 'Latitude' -Value $Lat
$LatLong | Add-Member -type NoteProperty -Name 'Longitude' -Value $Lng
}
ElseIf ($Status -eq 'ZERO_RESULTS') {
$LatLong | Add-Member -type NoteProperty -Name 'Latitude' -Value 0
$LatLong | Add-Member -type NoteProperty -Name 'Longitude' -Value 0
}
Else {
$ErrorMessage = $JSON.error_message
Write-Host -ForegroundColor Yellow "WARNING: Address geolocation failed for the following reason: $Status - $ErrorMessage"
$LatLong | Add-Member -type NoteProperty -Name 'Latitude' -Value 0
$LatLong | Add-Member -type NoteProperty -Name 'Longitude' -Value 0
}
}
Catch {
"Something went wrong. Please try again."
$EV.message
}
Return $LatLong
}
}