# Command Group 3: Policies

Manage voice policy assignments.

### `policies list [type]`

List available policies, optionally filtered by type.

```
teams-phone policies list [type] [OPTIONS]
```

**Arguments:**
| Argument | Description |
|----------|-------------|
| `[type]` | Policy type (optional): `calling`, `voicemail`, `emergency`, `emergency-routing`, `caller-id`, `dial-plan`, `voice-routing` |

**Options:**
| Option | Description |
|--------|-------------|
| `--show-assignments` | Include user count per policy |

**Data Source: PowerShell CSV Export**

⚠️ This command reads from `~/.teams-phone/cache/policies.csv` generated by PowerShell export script.

**Graph API Limitation:** No Graph API endpoint exists for listing policy definitions. The `effectivePolicyAssignments` field in `userConfigurations` shows which policies are assigned to users, but there's no endpoint to list all available policies by type.

**Policy Types Supported:**
- `TeamsCallingPolicy` → CLI type: `calling`
- `TeamsVoicemailPolicy` → CLI type: `voicemail`
- `CallingLineIdentity` → CLI type: `caller-id`
- `TenantDialPlan` → CLI type: `dial-plan`
- `OnlineVoiceRoutingPolicy` → CLI type: `voice-routing`
- `TeamsEmergencyCallingPolicy` → CLI type: `emergency`
- `TeamsEmergencyCallRoutingPolicy` → CLI type: `emergency-routing`

**⚠️ Known Limitation - Voicemail Policy:**
According to Graph API documentation, `TeamsVoicemailPolicy` is not supported in the batch policy assignment endpoint. However, it may work via the individual assignment endpoint. If voicemail policy assignment fails, users should use PowerShell: `Grant-CsOnlineVoicemailPolicy -Identity <user> -PolicyName <policy>`.

**Status:** Requires testing to confirm Graph API support for individual assignment.

**Degraded Mode:** If CSV file is missing or stale, command displays warning and may not show all available policies.

**Output Fields:**
- Policy Name
- Policy Type
- Description (if available)
- Is Global (Yes/No)
- Assigned Users (if --show-assignments, requires cross-referencing with user data)

**Example:**
```bash
# List all policy types
teams-phone policies list

# List only calling policies
teams-phone policies list calling

# List voicemail policies with assignment counts
teams-phone policies list voicemail --show-assignments
```

---

### `policies show <user>`

Show all policy assignments for a user.

```
teams-phone policies show <user> [OPTIONS]
```

**Arguments:**
| Argument | Description |
|----------|-------------|
| `<user>` | User identifier (UPN, display name, or object ID) |

**Output:**
Table showing all policy types and the user's assigned policy for each, including assignment source:
- Calling Policy (with assignment source: Direct or via Group)
- Voicemail Policy (with assignment source)
- Emergency Calling Policy (with assignment source)
- Emergency Call Routing Policy (with assignment source)
- Caller ID Policy (with assignment source)
- Dial Plan (with assignment source)
- Voice Routing Policy (with assignment source)

**Assignment Source:**
- **Direct**: Policy assigned directly to the user
- **Group**: Policy assigned via group membership (shows group name/ID)
- **Global**: User has no specific assignment (using tenant default)

**Note:** Understanding assignment source helps troubleshoot policy conflicts and manage group-based assignments.

**Example:**
```bash
# Show all policies for user
teams-phone policies show john.doe@contoso.com
```

---

### `policies assign <user> <policy-type> <policy-name>`

Assign a policy to a user.

```
teams-phone policies assign <user> <policy-type> <policy-name> [OPTIONS]
```

**Arguments:**
| Argument | Description |
|----------|-------------|
| `<user>` | User identifier |
| `<policy-type>` | Type of policy: `calling`, `voicemail`, `emergency`, `emergency-routing`, `caller-id`, `dial-plan`, `voice-routing` |
| `<policy-name>` | Name of the policy to assign (use "Global" for default) |

**Options:**
| Option | Description |
|--------|-------------|
| `--dry-run` | Preview assignment without making changes |
| `--force` | Skip confirmation prompt |

**Example:**
```bash
# Assign calling policy
teams-phone policies assign john.doe@contoso.com calling "AllowCalling"

# Assign voicemail policy with preview
teams-phone policies assign john.doe@contoso.com voicemail "TranscriptionEnabled" --dry-run

# Reset to global/default policy
teams-phone policies assign john.doe@contoso.com calling "Global"
```

---

### `policies bulk-assign <csv-file>`

Bulk assign policies from a CSV file.

```
teams-phone policies bulk-assign <csv-file> [OPTIONS]
```

**Arguments:**
| Argument | Description |
|----------|-------------|
| `<csv-file>` | Path to CSV file with policy assignments |

**Options:**
| Option | Description |
|--------|-------------|
| `--dry-run` | Validate and preview all assignments |
| `--continue-on-error` | Continue processing after failures |
| `--output <file>` | Write results to file |

**CSV Format:**
```csv
user,policy_type,policy_name
john.doe@contoso.com,calling,AllowCalling
jane.smith@contoso.com,voicemail,TranscriptionEnabled
```

**Example:**
```bash
# Preview bulk policy assignment
teams-phone policies bulk-assign policies.csv --dry-run

# Execute bulk assignment
teams-phone policies bulk-assign policies.csv --continue-on-error
```

---

