https://github.com/nitin27may/dotnet-cli
A .NET command-line utility framework for building versatile CLI tools. This repository includes examples for interacting with the Microsoft Graph API (Azure AD management) and executing HTTP requests. Features include fetching user details, listing group memberships, and performing HTTP operations with rich, formatted console output.
https://github.com/nitin27may/dotnet-cli
cli command command-line command-line-tool dotnet dotnet9
Last synced: about 2 months ago
JSON representation
A .NET command-line utility framework for building versatile CLI tools. This repository includes examples for interacting with the Microsoft Graph API (Azure AD management) and executing HTTP requests. Features include fetching user details, listing group memberships, and performing HTTP operations with rich, formatted console output.
- Host: GitHub
- URL: https://github.com/nitin27may/dotnet-cli
- Owner: nitin27may
- License: mit
- Created: 2025-01-02T21:53:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-02T21:58:19.000Z (over 1 year ago)
- Last Synced: 2026-01-06T20:18:20.819Z (5 months ago)
- Topics: cli, command, command-line, command-line-tool, dotnet, dotnet9
- Language: C#
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Command-Line Tool
A .NET command-line utility for interacting with Microsoft Graph API to fetch and manage user and group details in Azure Active Directory. The idea is that using this concept, you can make any command-line utility.
## Usage Examples
Query user details by:
- Network ID (SAM Account Name)
- Email address
- Display name
List user's group memberships with optional filtering
Search for groups by name
List group members with optional CSV export
Formatted console output using Spectre.Console
## Configuration
```json
{
"AzureAd": {
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"TenantId": "your-tenant-id"
}
}
```
## Installation
### Build and create package
```bash
dotnet pack -c Release -o ./nupkg
```
### Install globally
```bash
dotnet tool install --global --add-source ./nupkg graph
```
### Update existing installation
```bash
dotnet tool update --global --add-source ./nupkg graph
```
### Uninstall
```bash
dotnet tool uninstall --global graph
```
## Usage Examples
```bash
### Get User Details with all Groups in which the user is present
graph get-user --networkid USRNITIN --includegroup
### Get User Details with Groups which contain the character 'char'
graph get-user --networkid USRNITIN --includegroup true --groupfragment char
### Get User Details with Groups which contain the character 'char' and export the details
graph get-user --networkid USRNITIN --includegroup true --groupfragment char --export .\
### Search Group Name
graph get-group search --name MANAG
### Get all members of a group
graph get-group members --group GroupName
### Get all members of a group and export it
graph get-group members --group GroupName --csv .\
```
```bash
### GET Request:
graph http-request --method GET --url https://jsonplaceholder.typicode.com/posts/1
### POST Request:
graph http-request --method POST --url https://jsonplaceholder.typicode.com/posts --body '{"title": "foo", "body": "bar", "userId": 1}'
### GET Request with Headers:
graph http-request --method GET --url https://api.example.com/resource --headers "Authorization:Bearer xyz" "Accept:application/json"
```
### Installation using Artifact
```bash
dotnet nuget add source --name AzureArtifacts --username your_username --password https://dev.azure.com/your_organization/_packaging/your_feed_name/nuget/v3/index.json
```
```bash
dotnet tool install --global --add-source https://dev.azure.com/your_organization/_packaging/your_feed_name/nuget/v3/index.json graph
```
```bash
graph --version
```
Persist Environment Variables (Optional)
1. User Environment Variables: Add them to the user’s environment:
```powershell
[System.Environment]::SetEnvironmentVariable("AzureAd__ClientId", "your-client-id", "User")
[System.Environment]::SetEnvironmentVariable("AzureAd__ClientSecret", "your-client-secret", "User")
[System.Environment]::SetEnvironmentVariable("AzureAd__TenantId", "your-tenant-id", "User")
```
2. System Environment Variables: Add them to the system environment (requires admin privileges):
```powershell
[System.Environment]::SetEnvironmentVariable("AzureAd__ClientId", "your-client-id", "Machine")
[System.Environment]::SetEnvironmentVariable("AzureAd__ClientSecret", "your-client-secret", "Machine")
[System.Environment]::SetEnvironmentVariable("AzureAd__TenantId", "your-tenant-id", "Machine")
```
## Dependencies
- .NET 9.0
- Microsoft.Graph SDK
- System.CommandLine
- Azure.Identity
- Spectre.Console
## License
MIT