> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to a Microsoft Azure file share

> Connect the ABBYY FlexiCapture Application Server to a Microsoft Azure Files share, store credentials in Credential Manager, and set the IIS application pool.

You can connect the ABBYY FlexiCapture Application Server to a file share in Microsoft Azure.

<Note>
  It is assumed that a storage account has already been created in Microsoft Azure Files and is available for use by ABBYY FlexiCapture.
</Note>

1. On the Azure portal, go to your storage account (`abbyystorage` in this example) and click **Files** in the storage account pane.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_account_pane.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=a8d8d3e395085d39151626404c56c679" alt="Screenshot of the Microsoft Azure portal showing the abbyystorage storage account pane with the Files service highlighted." width="754" height="283" data-path="images/flexi-capture/Azure_account_pane.png" />
</Frame>

2. Create a new file share in your storage account by specifying its name (`fcstorage` in this example) and a space quota as required.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_new_file_share.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=4ca4ef6e666f7b42686246616548119b" alt="Screenshot of the Microsoft Azure portal where a new file share named fcstorage is being created with a specified name and quota." width="1380" height="283" data-path="images/flexi-capture/Azure_new_file_share.png" />
</Frame>

3. Open the created file share and click **Connect**.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_connect.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=cc1de0b7319fbfd035eda53a56504ef2" alt="Screenshot of the Microsoft Azure portal showing the created file share open with the Connect option selected." width="1176" height="296" data-path="images/flexi-capture/Azure_connect.png" />
</Frame>

4. Copy the `cmdkey` command to the Clipboard.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_cmdkey.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=68569de43cbabdc9ae52f73429015f24" alt="Screenshot of the Microsoft Azure portal Connect pane showing the cmdkey command being copied to the Clipboard." width="1159" height="632" data-path="images/flexi-capture/Azure_cmdkey.png" />
</Frame>

5. Log on to the virtual machine with the FlexiCapture Application Server as a system user with permissions to access the FlexiCapture services (`fcuser` in this example), open the command line prompt, and paste and execute the `cmdkey` command from the Clipboard. This will add the file share credentials to the Windows Credential Manager.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_cmdexe.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=1971f2c3fd9062e6d82ea27ea62a895b" alt="Screenshot of the Windows command line prompt where the cmdkey command is pasted and executed to add the file share credentials to Windows Credential Manager." width="809" height="341" data-path="images/flexi-capture/Azure_cmdexe.png" />
</Frame>

6. Open Windows Explorer and make sure that the user can access the file share.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_permissions.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=0ff570d9b7fc4733116f7ac998702732" alt="Screenshot of Windows Explorer confirming that the user can access the connected Azure file share." width="755" height="298" data-path="images/flexi-capture/Azure_permissions.png" />
</Frame>

7. Open the Internet Information Services (IIS) Manager, select the FlexiCapture application pool, and click **Advanced Settings**.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_iismanager.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=3713d245ddba87e66344190e93175e0d" alt="Screenshot of IIS Manager with the FlexiCapture application pool selected and the Advanced Settings option highlighted." width="962" height="264" data-path="images/flexi-capture/Azure_iismanager.png" />
</Frame>

8. Change the pool identity to the FlexiCapture user account with the required permissions, set **Load User Profile** to **True**, confirm the changes by clicking **OK**, and recycle the application pool.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_pool_identity.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=9588427b5b5ab41d1496a909a7d010d0" alt="Screenshot of the IIS Advanced Settings dialog with the application pool identity set to the FlexiCapture user account and Load User Profile set to True." width="1057" height="609" data-path="images/flexi-capture/Azure_pool_identity.png" />
</Frame>

9. In the Administration and Monitoring Console, select the **Use external file storage** option and specify the path to the file share in Microsoft Azure.

<Frame>
  <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Azure_new_db.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=de976cfe7b20af8c0601ad5c6f28d2c5" alt="Screenshot of the Administration and Monitoring Console with the Use external file storage option selected and the Microsoft Azure file share path specified." width="521" height="557" data-path="images/flexi-capture/Azure_new_db.png" />
</Frame>

## Use Azure Key Vault to connect to Microsoft Azure Files

Azure Key Vault is a cloud service for securely storing secrets, such as API keys, passwords, and certificates. The service enables Azure subscribers to protect their sensitive data used by cloud applications and services. You can create and manage key vaults through the Azure portal (see the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/key-vault/general/basic-concepts) for details).

To set up a connection to Azure Files:

### On the Azure portal

1. Set up virtual machines for your ABBYY FlexiCapture Application Servers.\
   **Important!** Your virtual machines with the Application Server installed must be registered in Azure Active Directory. For detailed instructions on how to create and set up virtual machines, see the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm#system-assigned-managed-identity).

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_1.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=addf5d2df73fc5ddeda024823a9acf7b" alt="Screenshot of the Azure portal showing a virtual machine for the ABBYY FlexiCapture Application Server registered in Azure Active Directory." width="1410" height="685" data-path="images/flexi-capture/File_storage_Azure_1.png" />
</Frame>

2. Create a new key vault. Under **Permission model**, select **Azure role-based access control**.

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_2.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=0dc5ddcb7ffb5a8accc2ba0ce9218a9b" alt="Screenshot of the Create a key vault page in the Azure portal with Azure role-based access control selected under Permission model." width="1407" height="572" data-path="images/flexi-capture/File_storage_Azure_2.png" />
</Frame>

3. To be able to save and view secrets, add the **Key Vault Secrets Officer** role for your account and the **Key Vault Secrets User** role for the virtual machine objects. For detailed instructions on how to grant permissions to virtual machines, see the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-arm).
4. Add your secret (that is, your access key) for your Azure Storage account to the key vault. For detailed instructions on how to add a secret to a key vault, see the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-portal#add-a-secret-to-key-vault).\
   **Important!** To connect to Azure Files, the name of your secret must be the same as your storage account name.

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_3.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=1a8031578f1c5fbef24344dddf1f643f" alt="Screenshot of the Azure portal where a secret is added to the key vault with the secret name matching the Azure Storage account name." width="1333" height="478" data-path="images/flexi-capture/File_storage_Azure_3.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_4.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=e8a99e9392f2122c03f9fcb6655284eb" alt="Screenshot of the Azure Storage account Access keys page in the Azure portal, where the access key used as the key vault secret is copied." width="1521" height="442" data-path="images/flexi-capture/File_storage_Azure_4.png" />
</Frame>

### On each Application Server

Configure your system account to access Azure Files. To do this:

1. Save the following PowerShell script on each virtual machine where the Application Server is installed:

```powershell theme={null}
Param(
    [Parameter(Mandatory=$true)][Alias("Share")][ValidateNotNullOrEmpty()][String]$ShareRoot,
    [Parameter(Mandatory=$true)][Alias("Uri")][ValidateNotNullOrEmpty()][String]$VaultUri
)

$StorageAccount = $ShareRoot | Select-String -pattern "(?<=\\)(.*?)(?=(\\|[.]))" | Select-Object -ExpandProperty Matches | Select-Object -ExpandProperty Value
$ShareUser = "Azure\" + $StorageAccount

# Get parameters from Azure Key Vault
$Response = Invoke-RestMethod -UseBasicParsing -Uri 'https://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -Method GET -Headers @{Metadata="true"}
$BearerToken = $Response.access_token

# SharePass
$Uri = ($VaultUri).TrimEnd('/') + "/secrets/" + $StorageAccount + "?api-version=2016-10-01"
$Response = Invoke-RestMethod -UseBasicParsing -Uri $Uri -Method GET -Headers @{Authorization="Bearer $BearerToken"}
$SharePass = $Response.value
$ShareCredential = New-Object PSCredential($ShareUser, (ConvertTo-SecureString -AsPlainText -Force -String $SharePass))

New-PSDrive -Name "Flexicapture" -PSProvider FileSystem -Root $ShareRoot -Credential $ShareCredential -Scope Global
```

The script accepts the following two parameters as input:

* The path to the root of the network Azure folder, for example: `\\<name of Azure Storage account>.file.core.windows.net\<name of network folder>`.
* The URI of the key vault storing the access key for your Azure Storage account. You can copy the URI from the **Vault URI** field on the **Overview** tab on the Azure portal.

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_5.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=2035d262c9172a9d2bc10d3b01d936c5" alt="Screenshot of the key vault Overview tab in the Azure portal with the Vault URI field highlighted." width="1755" height="336" data-path="images/flexi-capture/File_storage_Azure_5.png" />
</Frame>

Sample command for running the script:

```powershell theme={null}
powershell.exe <path to file with script> -share \\<name of Azure Storage account>.file.core.windows.net\<name of network folder> -uri https://<name of Azure key vault>.vault.azure.net/
```

2. To run the script, create a task in Task Scheduler that will be triggered by a system startup event. The task must be run under the System, Network Service, or Local Service user account. The same account must be used to run the IIS application pool.

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_6.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=b3ca334b0a2aaaaaecbd00e3ce79639d" alt="Screenshot of Task Scheduler showing a new task triggered by a system startup event." width="632" height="480" data-path="images/flexi-capture/File_storage_Azure_6.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_7.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=6718f173e9e638a04fcd71383fb43252" alt="Screenshot of the Task Scheduler task configured to run under the System account that also runs the IIS application pool." width="1224" height="631" data-path="images/flexi-capture/File_storage_Azure_7.png" />
</Frame>

3. Configure the IIS service to be started after the connection script is executed. To do this, open the **World Wide Web Publishing Service Properties** dialog box, and select **Automatic (Delayed Start)** from the **Startup type** drop-down list on the **General** tab.

<Frame>
  <img src="https://mintcdn.com/abbyy/IFr-A2MDVJd80FDs/images/flexi-capture/File_storage_Azure_8.png?fit=max&auto=format&n=IFr-A2MDVJd80FDs&q=85&s=808736bd756a29f23cac95a86b340266" alt="Screenshot of the World Wide Web Publishing Service Properties dialog with Startup type set to Automatic (Delayed Start)." width="406" height="468" data-path="images/flexi-capture/File_storage_Azure_8.png" />
</Frame>

4. Restart the Application Server.
