# Billing Tool Command Reference

The Billing tool commands are handy commands that interacts will the Billing  API service and Billing database to perform operations and to get different reports.

The Billing tool is usually found inside the update bundle that is shared during every release. To run the billing commands, navigate inside the 'BillingTool' folder, open an elevated PS window and execute the desired commands. The commands can be run in two ways.

* By passing the Billing API credentials as command parameters.

```
Example:
.\Billing.exe CollectAllLogs /days:5 /ApiEndpoint:https://localhost:44306 /Username:admin /Password:p@ssword
```

* Saving the Billing API credentials once in the tool config file (Billing.exe.config) and running the command alone.

Example:

![Billing API Credentials in Billing.exe.config file](/files/-MdueCBGUnEQr4oXpgFu)

```
.\Billing.exe CollectAllLogs /days:5
```

### Updating Billing Database

The command enables updating the Billing database. Before running the command, it would be good to ensure that the Billing database connection string is specified in 'C:\inetpub\MgmtSvc-CloudAssertBilling\Web.config' file.

![Billing database connection string in 'C:\inetpub\MgmtSvc-CloudAssertBilling\Web.config'' file.](/files/-MduhzYpeGuPdEouyyD0)

```
.\Billing.exe UpdateDatabase
```

### Monitor Billing Agent Health

The command gives the health of Billing Agent service.

```
.\Billing.exe GetUsageAggregationStatus
```

![Billing Agent Health](/files/-Mdujn9ooIpLGZ3P0lEc)

### Collecting Logs

The command collects all necessary logs and compresses it to a zip file. Passing the optional parameter '/days:' will collect the recent logs for the duration specified number of days. If the '/days' parameter is not specified, the tool will collect all the available billing logs.

```
.\Billing.exe CollectAllLogs /days:<int>

Example:
.\Billing.exe CollectAllLogs
```

![Log Collection for Troubleshooting Billing Resource Provider](/files/-MdukTN0Hi6iDshYcozm)

### Protect Config Files

The command will encrypt the config files.

```
.\Billing.exe SecureConfig "<file path>"

Example:
.\Billing.exe SecureConfig "C:\inetpub\MgmtSvc-CloudAssertBilling\Web.config"
```

### Unprotect Config Files

the command will decrypt the config files.

```
.\Billing.exe UnSecureConfig "<file path>"

Example:
.\Billing.exe UnSecureConfig "C:\inetpub\MgmtSvc-CloudAssertBilling\Web.config"
```

### Create Azure Stack Hub Stamp Connection

The command helps in creating a connection to Azure Stack Hub stamp so that the Cloud Assert Billing solution can query usage and compute cost for the same. The connection can be created either using azure app secret (AAD Integrated System) or certificate thumbprint (ADFS Integrated System). Refer '[Cost Management Across Multiple Azure Stack Hub Stamps](/azure-stack-billing/features/multi-stamp-azure-stack-hub.md)' to get the necessary inputs to create the connection.

#### Connection with App Secret

```
.\Billing.exe CreateAzureStackConnection <connectionName> <adminSubscriptionId> <tenantId> <applicaionId> <adminArmEndpoint> <tokenRequestResourceUrl> <authorityEndpointUrl> [/applicationSecret:<String>]              

Example:
.\Billing.exe CreateAzureStackConnection "Azs-Hub-01" "eeea58bf-9184-4b9a-8299-66c89a91f78c" "1e3cf5be-16b5-4c3c-9ca7-98a0074854a0" "c5543be6-78a3-4498-9b1d-2e225d6b2856" "https://adminmanagement.local.azurestack.external" "https://adminmanagement.cloudassertrp.onmicrosoft.com/b96b9a53-b9a0-4d73-a7fc-f8e27b1b53d5" "https://login.microsoftonline.com" /applicationSecret:"k+amxQUyMqXWN2Ug==" 
```

#### Connection with Certificate Thumbprint

```
.\Billing.exe CreateAzureStackConnection <connectionName> <adminSubscriptionId> <tenantId> <applicaionId> <adminArmEndpoint> <tokenRequestResourceUrl> <authorityEndpointUrl> [/certificateThumbprint:<String>] [/isAdfs]

Example:
.\Billing.exe CreateAzureStackConnection "Azs-Hub-02" "a7960fbc-a502-452a-8865-dcec48d20ed1" "cc4aa06d-3177-457a-a4b4-a4f8d4a5aa2d" "30fe4a8c-7eb6-4511-889d-8703fb3189e2" "https://adminmanagement.local.azurestack.external" "https://adminmanagement.adfs.azurestack.local/30fe4a8c-7eb6-4511-889d-8703fb3189e2" "https://adfs.local.mas500.samm.corp.cloudassert.com/adfs/" /certificateThumbprint:"39ae733bf3ba4fb7b4199d91b4103ea2316fd470" True
```

### Update VConnect API Credentials

The command save the VConnect API credentials in the Billing 'AppSettings' table. These credentials will be used to query VConnect usage, create tenant Azure Stack Hub connections, etc.

```
.\Billing.exe AddOrUpdateVConnectApiSettings <vconnectApiUrl> <vconnectApiUser> <vconnectApiPassword>

Example:
.\Billing.exe AddOrUpdateVConnectApiSettings "https://vconnect.cloudassert.local.azurestack.external:44305" "cloudassertadminuser" "p@ssword"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloudassert.com/azure-stack-billing/installation/configuration/billing-tool-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
