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

# Set up the PI AF extractor

> Install, configure, run, upgrade, and uninstall the Cognite PI AF extractor on Windows.

The Cognite PI AF extractor is distributed as a Windows installer (.msi file). When you run the .msi file, a setup wizard guides you through the installation process. The installer creates a Windows service and installs the binary files needed to run the extractor.

## Before you start

* Check the [server requirements](/cdf/integration/guides/extraction/pi_af/pi_af_server_requirements) for the PI AF extractor.

* Assing [access capabilities](/cdf/access/guides/capabilities#pi-af-extractor) in a CDF project.

<Tip>
  You can use OpenID Connect and your existing identity provider (IdP) framework to manage access to CDF data securely. [Read more](/cdf/integration/guides/extraction/admin_oidc).
</Tip>

* Set up a Windows Update schedule. Note that the update may reboot the machine, causing extractor downtime.

## Install and configure the extractor

<Steps>
  <Step title="Download and run the installer">
    Navigate to <span class="ui-element">Data fusion</span> > <span class="ui-element">Integrate</span> > <span class="ui-element">Extractors</span>  and download and run the latest PI AF Extractor .msi file.
  </Step>

  <Step title="Create a working directory">
    Create a working directory.

    <Info>
      Set Modify permission under **Properties** in the installation folder to avoid permission issues.
    </Info>
  </Step>

  <Step title="Create a configuration file">
    Create a `config` directory inside the working directory and create a configuration file according to the [configuration settings](/cdf/integration/guides/extraction/configuration/piaf). The file must be in YAML format.
  </Step>
</Steps>

## Run as a Windows service

<Steps>
  <Step title="Start the service">
    Start **PI AF Extractor service** from **Windows services**.
  </Step>

  <Step title="Verify the service is running">
    Verify that the service is running.
  </Step>

  <Step title="Set startup type">
    Open **Properties** for the service and set **Startup type** to **Automatic (Delayed Start)**.
  </Step>

  <Step title="Verify the extractor is running">
    Verify that the extractor is running. If you've configured the extractor to [log messages to a file](/cdf/integration/guides/extraction/configuration/piaf#logger), check the log files in the configured path, for instance, *logs/log.txt*.

    If you haven't configured the extractor to read updates, it terminates after one reading. Check any error messages in the log to verify a successful run.
  </Step>
</Steps>

## Run from a command line

You can run the extractor from a command line with these arguments:

| Argument               | Description                                                                                                                                                                      |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--host`               | Insert the PI server's host name or IP address.                                                                                                                                  |
| `--username`           | Insert the PI server's Windows username.                                                                                                                                         |
| `--password`           | Insert the PI server's Windows password.                                                                                                                                         |
| `--elements-query`     | Specify the query parameter for PI AF elements.                                                                                                                                  |
| `-s`\|`--service`      | Launch the extractor as a service. You must specify this parameter if you've configured a Windows service for the extractor. Running this from the command line only won't work. |
| `-f` \|`--config-file` | Set the path to the configuration file.                                                                                                                                          |
| `-l`\|`--log-level`    | Set the console log-level: `[fatal/error/warning/information/debug/verbose]`                                                                                                     |
| `-w`\|`--working-dir`  | Set the working directory for the extractor. The default value is the current directory for a stand-alone file or one level above the executable file for the service version.   |
| `--log-dir`            | Set the path to the log files to log to files unless you've already set the [Logger](/cdf/integration/guides/extraction/configuration/piaf#logger) configuration parameters.     |
| `-?`\|`-h+`\|--help    | Enter to show this information.                                                                                                                                                  |

## Upgrade the extractor

Download and run the .msi file for the new version of the extractor. The installer detects the current installation directory, updates the software, and keeps the configuration as-is. The sample configuration file is a part of the software package and is overwritten during an extractor upgrade.

<Steps>
  <Step title="Download the installer">
    Download the PI AF extractor .msi file from CDF.
  </Step>

  <Step title="Note current settings">
    Take note of the **installed version** in case of a rollback and of the **service properties** in the Properties dialog.

    <Warning>
      During the upgrade, the installer resets all custom service properties to their default values, such as the service recovery settings.
    </Warning>
  </Step>

  <Step title="Run the installer">
    Run the installer.
  </Step>

  <Step title="Restore custom properties">
    Update the custom service properties you noted in step 2.
  </Step>

  <Step title="Verify the upgrade">
    Verify that the extractor is running and that the version displayed in the *Starting PI Extractor* logline matches the upgraded version.
  </Step>
</Steps>

## Uninstall the extractor

<Steps>
  <Step title="Open the uninstaller">
    Run the installer, select **Remove the extractor** or open **Add or remove programs** from the Windows Control Panel.
  </Step>

  <Step title="Remove the extractor">
    Remove the **Cognite PI AF extractor**.
  </Step>

  <Step title="Optional. Clean up files">
    Optionally, remove the installation directory with the configuration file and logs.
  </Step>

  <Step title="Optional. Delete the installer">
    Optionally, delete the .msi file.
  </Step>
</Steps>
