PowerShell module for FleetDM API integration
A lightweight PowerShell module for interacting with the FleetDM Free Tier REST API.
FleetDM-PowerShell provides a native PowerShell interface to FleetDM Free Tier, enabling administrators to manage hosts, queries, policies, and software inventory through familiar PowerShell cmdlets. This module focuses on FleetDM’s free functionality without requiring Premium licenses or external dependencies.
📚 View Full Documentation - Comprehensive online documentation with detailed cmdlet reference
Install-Module -Name FleetDM-PowerShell -Force
# Clone the repository
git clone https://github.com/Jorgeasaurus/FleetDM-PowerShell.git
cd FleetDM-PowerShell
# Import directly without building
Import-Module ./FleetDM-PowerShell.psd1 -Force
# Using API token (recommended - most secure)
$token = ConvertTo-SecureString "your-api-token-here" -AsPlainText -Force
Connect-FleetDM -BaseUri "https://fleet.example.com" -ApiToken $token
# Using username/password
$cred = Get-Credential
Connect-FleetDM -BaseUri "https://fleet.example.com" -Credential $cred
# Get all hosts
Get-FleetHost
# Get specific host
Get-FleetHost -Id 123
# Filter hosts by status
Get-FleetHost -Status online
# Run a live query and get results directly
$results = Invoke-FleetQuery -Query "SELECT * FROM system_info;" -HostId 1,2,3
$results.Results | Format-Table
# Or use a saved query
$results = Invoke-FleetSavedQuery -QueryId 123 -HostId 1,2,3
# Get policies
Get-FleetPolicy
# Get software inventory
Get-FleetSoftware -VulnerableOnly
For detailed help and examples, visit the Online Documentation or use Get-Help <cmdlet-name> -Full
.
Connect-FleetDM
- Establish connection to FleetDM serverDisconnect-FleetDM
- Disconnect from FleetDM serverGet-FleetHost
- Retrieve host informationRemove-FleetHost
- Remove hosts from FleetDMGet-FleetQuery
- List saved queriesInvoke-FleetQuery
- Execute live queriesInvoke-FleetSavedQuery
- Execute saved queries with direct resultsGet-FleetPolicy
- Retrieve policiesNew-FleetPolicy
- Create new policiesSet-FleetPolicy
- Update existing policiesGet-FleetSoftware
- Retrieve software inventory (read-only)Invoke-FleetDMMethod
- Direct API access for unsupported endpoints# Find hosts offline for more than 30 days
$offlineHosts = Get-FleetHost -Status offline |
Where-Object { $_.seen_time -lt (Get-Date).AddDays(-30) }
# Remove them (with confirmation)
$offlineHosts | Remove-FleetHost -Confirm
# Get all policies with low compliance
Get-FleetPolicy |
Where-Object { $_.compliance_percentage -lt 80 } |
Format-Table name, compliance_percentage, failing_host_count
# Get all software with critical vulnerabilities
Get-FleetSoftware -VulnerableOnly |
Where-Object { $_.highest_severity -eq 'critical' } |
Sort-Object hosts_count -Descending |
Select-Object name, version, hosts_count, cve_count
# Get Ubuntu hosts and run a query
$ubuntuHosts = Get-FleetHost | Where-Object { $_.platform -eq 'ubuntu' }
$results = Invoke-FleetQuery -Query "SELECT * FROM os_version;" -HostId $ubuntuHosts.id
# View the results
$results.Results | ForEach-Object {
Write-Host "Host: $($_.HostId)"
$_.Rows | Format-Table
}
# Create a policy to check FileVault auto-login is disabled on macOS
New-FleetPolicy -Name "FileVault Auto-Login Disabled" `
-Query "SELECT 1 FROM managed_policies WHERE domain = 'com.apple.loginwindow' AND name = 'DisableFDEAutoLogin' AND value = 1 LIMIT 1;" `
-Platform darwin
# Import policies from CSV
Import-Csv policies.csv | ForEach-Object {
New-FleetPolicy -Name $_.Name -Query $_.Query -Description $_.Description
}
All cmdlets support pipeline operations:
# Chain operations - get online Windows hosts
Get-FleetHost -Status online |
Where-Object { $_.platform -eq 'ubuntu' } |
Select-Object id, hostname, seen_time
# Execute query on filtered hosts
$hostIds = Get-FleetHost |
Where-Object { $_.platform -eq 'debian' } |
Select-Object -First 5 -ExpandProperty id
Invoke-FleetQuery -Query "SELECT * FROM system_info;" -HostId $hostIds
# Or pipe host IDs directly as an array
@(17,6,8) | Invoke-FleetQuery -Query "SELECT * FROM os_version;"
The module provides detailed error messages and supports standard PowerShell error handling:
try {
Get-FleetHost -Id 99999
}
catch {
Write-Error "Failed to get host: $_"
}
The most secure method is using API tokens:
fleetctl user create --api-only
# Store token securely
$token = Read-Host "Enter API Token" -AsSecureString
Connect-FleetDM -BaseUri "https://fleet.example.com" -ApiToken $token
Less secure but available when tokens aren’t accessible:
$cred = Get-Credential
Connect-FleetDM -BaseUri "https://fleet.example.com" -Credential $cred
For developers who want to contribute or modify the module:
# Clone the repository
git clone https://github.com/Jorgeasaurus/FleetDM-PowerShell.git
cd FleetDM-PowerShell
# Import the module directly from source
Import-Module ./FleetDM-PowerShell.psd1 -Force
# Make your changes and test them
Run the Pester tests:
# Run all tests
Invoke-Pester
# Run specific test file
Invoke-Pester -Path .\Tests\Get-FleetHost.Tests.ps1
# Run with code coverage
Invoke-Pester -CodeCoverage @('Public\*.ps1', 'Private\*.ps1')
-Label
or -All
return campaign info only# Test connection
Test-NetConnection -ComputerName fleet.example.com -Port 443
# Enable verbose output
Connect-FleetDM -BaseUri "https://fleet.example.com" -ApiToken $token -Verbose
# For self-signed certificates (not recommended for production)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
# Force reload module
Remove-Module FleetDM-PowerShell -Force -ErrorAction SilentlyContinue
Import-Module FleetDM-PowerShell -Force -Verbose
# Or import directly from source
Import-Module ./FleetDM-PowerShell.psd1 -Force
Contributions are welcome! Please:
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)The project uses GitHub Actions for continuous integration:
This project is licensed under the MIT License - see the LICENSE file for details.
Get-Help <cmdlet-name> -Full
for detailed cmdlet documentation./Show-Documentation.ps1
for local documentation browsing