22# Licensed under the MIT License.
33
44Write-Host " Ensuring Azure dependencies are installed."
5- Install-Module - Name Az
6- Import-Module - Name Az
7- Install-Module - Name Az.Search
8- Import-Module - Name Az.Search
5+ if (! (Get-Module - Name Az)) {
6+ Write-Host " Installing Az PowerShell..."
7+ Install-Module - Name Az
8+ Import-Module - Name Az
9+ }
10+ if (! (Get-Module - Name Az.Search)) {
11+ Write-Host " Installing Az.Search PowerShell..."
12+ Install-Module - Name Az.Search
13+ Import-Module - Name Az.Search
14+ }
915
1016Write-Host @"
1117
@@ -155,26 +161,16 @@ function Deploy
155161 - Name $storageContainerName `
156162 - Context $storageContext `
157163 - Permission Off
158- }
159-
160- CreateStorageAccountAndContainer;
161-
162164
163- function UploadSampleDocuments
164- {
165165 Write-Host " Uploading sample_documents directory" ;
166-
167- # Note: These use the "Azure" api instead of the "Az" api.
168- $storageContext = New-AzureStorageContext `
169- - StorageAccountName $storageAccountName `
170- - StorageAccountKey $global :storageAccountKey
171-
172166 Push-Location " ../sample_documents"
173- ls - File - Recurse | Set-AzureStorageBlobContent - Container $storageContainerName - Context $storageContext - Force
167+ ls - File - Recurse | Set-AzStorageBlobContent - Container $storageContainerName - Context $storageContext - Force
174168 Pop-Location
175169 }
176170
177- UploadSampleDocuments;
171+ CreateStorageAccountAndContainer;
172+
173+
178174
179175
180176 function CreateSearchServices
@@ -193,10 +189,9 @@ function Deploy
193189 # Create a new search service
194190 # Alternatively, you can now use the Az.Search module: https://docs.microsoft.com/en-us/azure/search/search-manage-powershell
195191 Write-Host " Creating Search Service" ;
196- $searchService = New-AzResourceGroupDeployment `
192+ $searchService = New-AzSearchService `
197193 - ResourceGroupName $resourceGroupName `
198- - TemplateUri " https://gallery.azure.com/artifact/20151001/Microsoft.Search.1.0.9/DeploymentTemplates/searchServiceDefaultTemplate.json" `
199- - NameFromTemplate $searchServiceName `
194+ - Name $searchServiceName `
200195 - Sku $searchSku - Location $location `
201196 - PartitionCount 1 `
202197 - ReplicaCount 1
@@ -301,29 +296,21 @@ function Deploy
301296
302297 CreateWebApp;
303298
304-
305- function WriteAppSettings
299+ function PrintAppsettings
306300 {
307- Write-Host " Writing App Settings" ;
308-
309- # Read the existing settings.
310- $filePath = " ..\02 - Web UI Template\CognitiveSearch.UI\appsettings.json"
311- $file = ([System.IO.File ]::ReadAllText($filePath ) | ConvertFrom-Json )
312-
313- # Update the values.
314- $file.SearchServiceName = $searchServiceName
315- $file.SearchApiKey = $global :searchServiceKey
316- $file.SearchIndexName = $indexName
317- $file.SearchIndexerName = $indexerName
318- $file.StorageAccountName = $storageAccountName
319- $file.StorageAccountKey = $global :storageAccountKey
320- $file.StorageContainerAddress = (" https://" + $storageAccountName + " .blob.core.windows.net/" + $storageContainerName )
321-
322- # Write the settings to the file.
323- $file | ConvertTo-Json | Out-File - FilePath $filePath - Encoding utf8 - Force
301+ Write-Host " Copy and paste the following values to update the appsettings.json file described in the next folder:" ;
302+ Write-Host " ------------------------------------------------------------" ;
303+ Write-Host " SearchServiceName: '$searchServiceName '" ;
304+ Write-Host " SearchApiKey: '$global :searchServiceKey '" ;
305+ Write-Host " SearchIndexName: '$indexName '" ;
306+ Write-Host " SearchIndexerName: '$indexerName '" ;
307+ Write-Host " StorageAccountName: '$storageAccountName '" ;
308+ Write-Host " StorageAccountKey: '$global :storageAccountKey '" ;
309+ $StorageContainerAddress = (" https://" + $storageAccountName + " .blob.core.windows.net/" + $storageContainerName )
310+ Write-Host " StorageContainerAddress: '$StorageContainerAddress '" ;
311+ Write-Host " ------------------------------------------------------------" ;
324312 }
325-
326- WriteAppSettings;
313+ PrintAppsettings;
327314}
328315
329316Deploy;
0 commit comments