PSRedfish is a universal PowerShell client for the DMTF Redfish® standard. It provides a simple, vendor-neutral interface for managing servers and infrastructure using the Redfish API.
- Pure Redfish Implementation: No vendor-specific code - works with any Redfish-compliant endpoint
- High Performance: Uses .NET HttpClient for optimal performance
- Session Management: Built-in session caching and lifecycle management
- Pipeline Support: All cmdlets support PowerShell pipeline operations
- Comprehensive Error Handling: Detailed error messages with Redfish extended information
Creates an authenticated session to a Redfish API endpoint.
# Create a session with session-based authentication (default, recommended)
$cred = Get-Credential
$session = New-RedfishSession -BaseUri 'https://redfish.example.com' -Credential $cred
# Create a session with HTTP Basic authentication
$session = New-RedfishSession -BaseUri 'https://redfish.example.com' -Credential $cred -AuthMethod Basic
# With custom timeout
$session = New-RedfishSession -BaseUri 'https://192.168.1.100' -Credential $cred -TimeoutSeconds 60
# Skip certificate validation (not recommended for production)
$session = New-RedfishSession -BaseUri 'https://192.168.1.100' -Credential $cred -SkipCertificateCheckAuthentication Methods:
- Session (default): Creates a Redfish session and uses X-Auth-Token for subsequent requests. More secure and recommended.
- Basic: Uses HTTP Basic Authentication for all requests. Simpler but less secure.
Executes HTTP requests against Redfish endpoints.
# GET request
$systems = Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/Systems'
# POST request
$body = @{
ResetType = 'ForceRestart'
}
Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/Systems/1/Actions/ComputerSystem.Reset' -Method POST -Body $body
# PATCH request to update properties
$body = @{
AssetTag = 'SERVER-001'
}
Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/Systems/1' -Method PATCH -Body $body
# DELETE request
Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/SessionService/Sessions/1' -Method DELETERetrieves active sessions from the session cache.
# Get all active sessions
$sessions = Get-RedfishSession
# Filter by BaseUri
$sessions = Get-RedfishSession -BaseUri 'https://redfish.example.com'Properly disposes of a session and cleans up resources.
# Remove a specific session
Remove-RedfishSession -Session $session
# Remove all sessions via pipeline
Get-RedfishSession | Remove-RedfishSession# Import the module
Import-Module PSRedfish
# Create session
$cred = Get-Credential
$session = New-RedfishSession -BaseUri 'https://192.168.1.100' -Credential $cred
# Get service root
$serviceRoot = Invoke-RedfishRequest -Session $session -Uri '/redfish/v1'
Write-Host "Connected to: $($serviceRoot.Name) - $($serviceRoot.RedfishVersion)"
# List all computer systems
$systems = Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/Systems'
foreach ($systemLink in $systems.Members) {
$system = Invoke-RedfishRequest -Session $session -Uri $systemLink.'@odata.id'
Write-Host "System: $($system.Name) - $($system.PowerState)"
}
# Update asset tag
$updateBody = @{
AssetTag = 'PROD-SERVER-001'
}
Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/Systems/1' -Method PATCH -Body $updateBody -WhatIf
# Clean up
Remove-RedfishSession -Session $session# Process multiple systems from pipeline
$systems.Members | ForEach-Object {
Invoke-RedfishRequest -Session $session -Uri $_.'@odata.id'
} | Select-Object Name, PowerState, Model
# Clean up all sessions
Get-RedfishSession | Remove-RedfishSessiontry {
$system = Invoke-RedfishRequest -Session $session -Uri '/redfish/v1/Systems/Invalid'
}
catch {
Write-Error "Failed to get system: $_"
# Error includes HTTP status code and Redfish extended info
}Some older BMCs may not support session authentication. Use this pattern for compatibility:
try {
# Try session authentication first (more secure)
$session = New-RedfishSession -BaseUri $uri -Credential $cred -AuthMethod Session
}
catch {
Write-Warning "Session authentication failed: $_"
Write-Host 'Falling back to Basic authentication...'
$session = New-RedfishSession -BaseUri $uri -Credential $cred -AuthMethod Basic
}
finally {
if ($session) {
Remove-RedfishSession -Session $session
}
}# Connect to multiple servers
$session1 = New-RedfishSession -BaseUri 'https://server1.example.com' -Credential $cred
$session2 = New-RedfishSession -BaseUri 'https://server2.example.com' -Credential $cred
# List all active sessions
$allSessions = Get-RedfishSession
foreach ($s in $allSessions) {
Write-Host "$($s.BaseUri) - $($s.AuthMethod)"
}
# Clean up all at once
Get-RedfishSession | Remove-RedfishSession-
Always Clean Up Sessions
try { $session = New-RedfishSession -BaseUri $uri -Credential $cred # ... do work ... } finally { Remove-RedfishSession -Session $session }
-
Use -WhatIf for Destructive Operations
Invoke-RedfishRequest -Session $session -Uri $uri -Method DELETE -WhatIf
-
Enable Verbose Logging for Troubleshooting
$session = New-RedfishSession -BaseUri $uri -Credential $cred -Verbose Invoke-RedfishRequest -Session $session -Uri $uri -Verbose
-
Leverage Redfish OData Navigation
# Follow @odata.id references $systemUri = $systems.Members[0].'@odata.id' $system = Invoke-RedfishRequest -Session $session -Uri $systemUri
- Never use
-SkipCertificateCheckin production environments - Store credentials securely (use
Get-Credentialor secure vaults) - Always dispose of sessions when done to prevent resource leaks
- Use HTTPS endpoints whenever possible
Increase timeout if connecting to slow endpoints:
$session = New-RedfishSession -BaseUri $uri -Credential $cred -TimeoutSeconds 120For development/testing only:
$session = New-RedfishSession -BaseUri $uri -Credential $cred -SkipCertificateCheckEnable verbose output for detailed debugging:
$VerbosePreference = 'Continue'
$session = New-RedfishSession -BaseUri $uri -Credential $cred -Verbose