Functions/Public/Get-MinionKeyState.ps1
<#
.SYNOPSIS Gets the state of a Minions key. .DESCRIPTION This function will use the Invoke-SaltStackAPIMethod command to query the get_minion_key_state method on the minions resource to return a minion's key state. .EXAMPLE Get-MinionKeyState -SaltConnection $SaltConnection -MinionID 'minionname.domain.local' This will return the key state of a minion id. .EXAMPLE Get-MinionKeyState -SaltConnection $SaltConnection -MinionID 'minionname.domain.local' -KeyState accepted This will return minion key state of a minion if it is in the "accepted" state. Otherwise, the return will be empty. .EXAMPLE Get-MinionKeyState -SaltConnection $SaltConnection -KeyState pending This will return minion key states that are "pending". .OUTPUTS PSCustomObject .NOTES General notes .LINK #> function Get-MinionKeyState { [CmdletBinding(SupportsShouldProcess = $true)] param ( # Salt connection object [Parameter(Mandatory = $true)] [SaltConnection] $SaltConnection, # MinionID [String] $MinionID, # KeyState [String] [Validateset('pending','accepted','rejected','denied')] $KeyState ) $arguments = @{} # Sets no limit to the number of results to return $arguments.Add('limit','0') if ($MinionID) { if ($KeyState) { # MinionID and KeyState specified $arguments.Add('minion_id',$minionID) $arguments.Add('key_state',$KeyState) } else { # Only MinionID Specified $arguments.Add('minion_id',$minionID) } } elseif ($KeyState) { # Only KeyState provided $arguments.Add('key_state',$KeyState) } $return = Invoke-SaltStackAPIMethod -SaltConnection $SaltConnection -Resource minions -Method get_minion_key_state -Arguments $arguments if ($return.error) { $errorDetail = $return.error.detail.state $errorMessage = $return.error.message Write-Error "$errorMessage - $errorDetail" } else { $results = $return.ret.results Write-Output -InputObject $results } } |