Skip to content

Commit

Permalink
Get-TssDistributedEngineServerCapabilities - new command to pull the …
Browse files Browse the repository at this point in the history
…OS details of a DE
  • Loading branch information
wsmelton committed Oct 8, 2021
1 parent cb5f132 commit 8e77a5a
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Get-TssDistributedEngineServerCapabilities

## SYNOPSIS
Get the server capabilities for a Distributed Engine

## SYNTAX

```
Get-TssDistributedEngineServerCapabilities [-TssSession] <Session> -Id <Int32[]> [<CommonParameters>]
```

## DESCRIPTION
Get the server capabilities for a Distributed Engine

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssDistributedEngineServerCapabilities -TssSession $session -Id 5
```

Return server capabilities for Distributed Engine Id 5

## 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
```
### -Id
Short description for parameter
```yaml
Type: Int32[]
Parameter Sets: (All)
Aliases: EngineId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
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.DistributedEngine.ServerCapabilities
## NOTES
Requires TssSession object returned by New-TssSession
## RELATED LINKS
[https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/Get-TssDistributedEngineServerCapabilities](https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/Get-TssDistributedEngineServerCapabilities)
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/Get-TssDistributedEngineServerCapabilities.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/Get-TssDistributedEngineServerCapabilities.ps1)
50 changes: 50 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -3710,5 +3710,55 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.DistributedEngines.ServerCapabilities -->
<View>
<Name>DistributedEngines.ServerCapabilities</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.DistributedEngines.ServerCapabilities</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>ComputerName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>OperatingSystemVersion</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Architecture</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ProcessorCount</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>DotNetVersion</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ServiceAccountName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ServiceAccountCanRestartService</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>LastModifiedDate</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.DistributedEngines
{
public class ServerCapabilities
{
public int DotNetRelease { get; set; }
public string DotNetVersion { get; set; }
public string OperatingSystemVersion { get; set; }
public string OperatingSystemPlatform { get; set; }
public string OperatingSystemServicePack { get; set; }
public string Architecture { get; set; }
public string InstallationPath { get; set; }
public string ComputerName { get; set; }
public int ProcessorCount { get; set; }
public string PowerShellVersion { get; set; }
public string SystemDirectory { get; set; }
public string ServiceAccountName { get; set; }
public bool ServiceAccountCanRestartService { get; set; }
public DateTime? LastModifiedDate { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function Get-TssDistributedEngineServerCapabilities {
<#
.SYNOPSIS
Get the server capabilities for a Distributed Engine
.DESCRIPTION
Get the server capabilities for a Distributed Engine
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssDistributedEngineServerCapabilities -TssSession $session -Id 5
Return server capabilities for Distributed Engine Id 5
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/Get-TssDistributedEngineServerCapabilities
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/Get-TssDistributedEngineServerCapabilities.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.DistributedEngine.ServerCapabilities')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias("EngineId")]
[int[]]
$Id
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
foreach ($engine in $Id) {
$uri = $TssSession.ApiUrl, 'distributed-engine', $engine, 'server-capabilities' -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 server capabilities for Distributed Engine [$engine]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
. $GetServerCapabilities $restResponse
}
}
} else {
Write-Warning "No valid session found"
}
}
}
37 changes: 37 additions & 0 deletions src/parts/GetServerCapabilities.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
param(
[Parameter(Position = 0)]
[PSCustomObject]$Object
)

<# determine .NET Version #>
$dotnetversionNum = $Object.Where({ $_.Name -eq 'DotNetVersion' }).Value
$dotnetversionString = switch ($dotnetversionNum) {
378389 { '.Net Framework 4.5' }
{ $_ -in 378675,378758 } { '.Net Framework 4.5.1' }
379893 { '.Net Framework 4.5.2' }
{ $_ -in 393295,393297 } { '.Net Framework 4.6' }
{ $_ -in 394254,394271 } { '.Net Framework 4.6.1' }
{ $_ -in 394802,394806 } { '.Net Framework 4.6.2' }
{ $_ -in 460798,460805 } { '.Net Framework 4.7' }
{ $_ -in 461308,461310 } { '.Net Framework 4.7.1' }
{ $_ -in 461808,461814 } { '.Net Framework 4.7.2' }
{ $_ -in 528040,528372,528049 } { '.Net Framework 4.8' }
default { 'Unknown' }
}

[Thycotic.PowerShell.DistributedEngines.ServerCapabilities]@{
DotNetRelease = $Object.Where({ $_.Name -eq 'DotNetVersion' }).value
DotNetVersion = $dotnetversionString
OperatingSystemVersion = $Object.Where({ $_.Name -eq 'OperatingSystemVersion' }).value
OperatingSystemPlatform = $Object.Where({ $_.Name -eq 'OperationSystemPlatform' }).value
OperatingSystemServicePack = $Object.Where({ $_.Name -eq 'OperatingSystemServicePack' }).value
Architecture = $Object.Where({ $_.Name -eq 'Architecture' }).value
InstallationPath = $Object.Where({ $_.Name -eq 'Directory' }).value
ComputerName = $Object.Where({ $_.Name -eq 'ComputerName' }).value
ProcessorCount = $Object.Where({ $_.Name -eq 'NumberOfProcessors' }).value
PowerShellVersion = $Object.Where({ $_.Name -eq 'PowerShell3Version' }).value
SystemDirectory = $Object.Where({ $_.Name -eq 'SystemDirectory' }).value
ServiceAccountName = $Object.Where({ $_.Name -eq 'EngineServiceAccount_Name' }).value
ServiceAccountCanRestartService = $Object.Where({ $_.Name -eq 'EngineServiceAccount_HasRightToStartService' }).value
LastModifiedDate = $Object[0].lastModifiedDate
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id'
[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.DistributedEngines.ServerCapabilities" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.DistributedEngines.ServerCapabilities'
}
}
}

0 comments on commit 8e77a5a

Please sign in to comment.