diff --git a/docs/commands/discovery/Get-TssDiscoveryStatus.md b/docs/commands/discovery/Get-TssDiscoveryStatus.md new file mode 100644 index 00000000..ce58d920 --- /dev/null +++ b/docs/commands/discovery/Get-TssDiscoveryStatus.md @@ -0,0 +1,58 @@ +# Get-TssDiscoveryStatus + +## SYNOPSIS +Get status of Discovery + +## SYNTAX + +``` +Get-TssDiscoveryStatus [-TssSession] [] +``` + +## DESCRIPTION +Get status of Discovery + +## EXAMPLES + +### EXAMPLE 1 +``` +$session = New-TssSession -SecretServer https://alpha -Credential $ssCred +Get-TssDiscoveryStatus -TssSession $session - some test value +``` + +Add minimum example for each parameter + +## PARAMETERS + +### -TssSession +TssSession object created by New-TssSession for authentication + +```yaml +Type: Session +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### Thycotic.PowerShell.Discovery.Status +## NOTES +Requires TssSession object returned by New-TssSession + +## RELATED LINKS + +[https://thycotic-ps.github.io/thycotic.secretserver/commands/discovery/Get-TssDiscoveryStatus](https://thycotic-ps.github.io/thycotic.secretserver/commands/discovery/Get-TssDiscoveryStatus) + +[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/discovery/Get-TssDiscoveryStatus.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/discovery/Get-TssDiscoveryStatus.ps1) + diff --git a/src/Thycotic.SecretServer.Format.ps1xml b/src/Thycotic.SecretServer.Format.ps1xml index 95f2e2b7..5fadfc0f 100644 --- a/src/Thycotic.SecretServer.Format.ps1xml +++ b/src/Thycotic.SecretServer.Format.ps1xml @@ -3271,5 +3271,51 @@ + + + Discovery.Status + + Thycotic.PowerShell.Discovery.Status + + + + + + + + + + + + + + + + ComputerScanDuration + + + ComputerScanStartDateTime + + + ComputerScanEndDateTime + + + DiscoveryDuration + + + DiscoveryStartDateTime + + + DiscoveryEndDateTime + + + DiscoverySourceCount + + + + + + + diff --git a/src/Thycotic.SecretServer.Types.ps1xml b/src/Thycotic.SecretServer.Types.ps1xml index 079701d0..f3f12e73 100644 --- a/src/Thycotic.SecretServer.Types.ps1xml +++ b/src/Thycotic.SecretServer.Types.ps1xml @@ -304,4 +304,21 @@ + + Thycotic.PowerShell.Discovery.Status + + + DiscoveryDuration + + ($this.DiscoveryEndDateTime - $this.DiscoveryStartDateTime) + + + + ComputerScanDuration + + ($this.ComputerScanEndDateTime - $this.ComputerScanStartDateTime) + + + + \ No newline at end of file diff --git a/src/Thycotic.SecretServer/classes/discovery/Status.cs b/src/Thycotic.SecretServer/classes/discovery/Status.cs new file mode 100644 index 00000000..0f715932 --- /dev/null +++ b/src/Thycotic.SecretServer/classes/discovery/Status.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; +using System.Management.Automation; +using System.Management.Automation.Runspaces; +using Thycotic.PowerShell.Enums; + +namespace Thycotic.PowerShell.Discovery +{ + public class Status + { + public DiscoveryActionType[] Actions { get; set; } + public DateTime? ComputerScanEndDateTime { get; set; } + public DateTime? ComputerScanStartDateTime { get; set; } + public DateTime? DiscoveryEndDateTime { get; set; } + public DateTime? DiscoveryStartDateTime { get; set; } + public int DiscoverySourceCount { get; set; } + public bool IsComputerScanRunning { get; set; } + public bool IsDiscoveryEnabled { get; set; } + public bool IsDiscoveryRunning { get; set; } + public DateTime? NextComputerScanStart { get; set; } + public DateTime? NextDiscoveryStart { get; set; } + } +} \ No newline at end of file diff --git a/src/Thycotic.SecretServer/enums/discovery/DiscoveryActionType.cs b/src/Thycotic.SecretServer/enums/discovery/DiscoveryActionType.cs new file mode 100644 index 00000000..d5ae8341 --- /dev/null +++ b/src/Thycotic.SecretServer/enums/discovery/DiscoveryActionType.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using System.Management.Automation; +using System.Management.Automation.Runspaces; + +namespace Thycotic.PowerShell.Enums +{ + public enum DiscoveryActionType + { + CreateDiscoverySource, + EditConfiguration, + EditDiscoverySource, + RunComputerScan, + RunDiscovery, + ViewScanners + } +} \ No newline at end of file diff --git a/src/functions/discovery/Get-TssDiscoveryStatus.ps1 b/src/functions/discovery/Get-TssDiscoveryStatus.ps1 new file mode 100644 index 00000000..33dc1b4f --- /dev/null +++ b/src/functions/discovery/Get-TssDiscoveryStatus.ps1 @@ -0,0 +1,74 @@ +function Get-TssDiscoveryStatus { + <# + .SYNOPSIS + Get status of Discovery + + .DESCRIPTION + Get status of Discovery + + .EXAMPLE + $session = New-TssSession -SecretServer https://alpha -Credential $ssCred + Get-TssDiscoveryStatus -TssSession $session - some test value + + Add minimum example for each parameter + + .LINK + https://thycotic-ps.github.io/thycotic.secretserver/commands/discovery/Get-TssDiscoveryStatus + + .LINK + https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/discovery/Get-TssDiscoveryStatus.ps1 + + .NOTES + Requires TssSession object returned by New-TssSession + #> + [CmdletBinding()] + [OutputType('Thycotic.PowerShell.Discovery.Status')] + param ( + # TssSession object created by New-TssSession for authentication + [Parameter(Mandatory,ValueFromPipeline,Position = 0)] + [Thycotic.PowerShell.Authentication.Session] + $TssSession + ) + begin { + $tssParams = $PSBoundParameters + $invokeParams = . $GetInvokeApiParams $TssSession + } + process { + Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" + if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { + . $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation + $uri = $TssSession.ApiUrl, 'discovery', 'status' -join '/' + $invokeParams.Uri = $uri + $invokeParams.Method = 'GET' + + Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri)" + try { + $apiResponse = Invoke-TssApi @invokeParams + $restResponse = . $ProcessResponse $apiResponse + } catch { + Write-Warning "Issue getting Discovery status" + $err = $_ + . $ErrorHandling $err + } + + if ($restResponse) { + $result = [Thycotic.PowerShell.Discovery.Status]@{ + Actions = $restResponse.actions + ComputerScanEndDateTime = $restResponse.discoveryComputerScanEndDateTime + ComputerScanStartDateTime = $restResponse.discoveryComputerScanStartDateTime + DiscoveryEndDateTime = $restResponse.discoveryFetchEndDateTime + DiscoveryStartDateTime = $restResponse.discoveryFetchStartDateTime + DiscoverySourceCount = $restResponse.discoverySourceCount + IsComputerScanRunning = $restResponse.isDiscoveryComputerScanRunning + IsDiscoveryEnabled = $restResponse.isDiscoveryEnabled + IsDiscoveryRunning = $restResponse.isDiscoveryFetchRunning + NextComputerScanStart = $restResponse.nextComputerScanDiscoveryDateTime + NextDiscoveryStart = $restResponse.nextFetchDiscoveryDateTime + } + return $result + } + } else { + Write-Warning "No valid session found" + } + } +} \ No newline at end of file diff --git a/tests/discovery/Get-TssDiscoveryStatus.Tests.ps1 b/tests/discovery/Get-TssDiscoveryStatus.Tests.ps1 new file mode 100644 index 00000000..2079425f --- /dev/null +++ b/tests/discovery/Get-TssDiscoveryStatus.Tests.ps1 @@ -0,0 +1,24 @@ +BeforeDiscovery { + $commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf +} +Describe "$commandName verify parameters" { + BeforeDiscovery { + [object[]]$knownParameters = 'TssSession' + [object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys + [object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') + $unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru + } + Context "Verify parameters" -Foreach @{currentParams = $currentParams } { + It "$commandName should contain <_> parameter" -TestCases $knownParameters { + $_ -in $currentParams | Should -Be $true + } + It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { + $_ | Should -BeNullOrEmpty + } + } + Context "Command specific details" { + It "$commandName should set OutputType to Thycotic.PowerShell.Discovery.Status" -TestCases $commandDetails { + $_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Discovery.Status' + } + } +} \ No newline at end of file