Skip to content

Commit

Permalink
Merge pull request #2 from EliteLoser/dev
Browse files Browse the repository at this point in the history
Merging dev v2 into master
  • Loading branch information
EliteLoser authored Jan 1, 2018
2 parents ffc0144 + 7342be9 commit 229aa61
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ There is also fairly extensive built-in documentation.

You can suppress the ansible-styled output by passing the -Quiet switch parameter to Invoke-SshCommand, if you only want to collect results and process them programmatically, with no visual feedback on the way, which is useful if there's a lot of text returned.

![alt tag](/SSHSessions-example-2017-11-11.png)
![alt tag](/SSH-Sessions-v2-objects-demo.png)
Binary file added SSH-Sessions-v2-objects-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions SSHSessions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Svendsen Tech.

Import-Module -Name Pester -ErrorAction Stop #-Verbose:$False
$VerbosePreference = "SilentlyContinue"
#$ComputerName = "www.svendsentech.no"
$ComputerName = ""
$ComputerName = "www.svendsentech.no"
#$ComputerName = ""

Import-Module -Name SSHSessions -ErrorAction Stop #-Verbose:$False

Expand All @@ -22,7 +22,7 @@ if ($ComputerName -eq "") {

Describe SshSessions {

It "Test New-SshSession" {
It "New-SshSession creates a new SSH session successfully to the test target." {
if ((Get-SshSession -ComputerName $ComputerName).Connected -eq $True) {
Write-Verbose -Message "Terminating existing SSH session to $ComputerName." -Verbose
$Null = Remove-SshSession -ComputerName $ComputerName -ErrorAction SilentlyContinue
Expand All @@ -31,24 +31,24 @@ Describe SshSessions {
$Result | Should -Be "[$ComputerName] Successfully connected."
}

It "Test Invoke-SshCommand. Verify simple echo statement output is as expected" {
It "Invoke-SshCommand produces expected simple remote 'echo' test output." {
$Result = Invoke-SshCommand -ComputerName $ComputerName -Quiet -Command "echo 'This is a test'" -ErrorAction Stop
$Result[0] | Should -Be "This is a test"
$Result[0].Result | Should -Be "This is a test"
}

It "Test piping Get-SshSession to Invoke-SshCommand" {
It "Piping Get-SshSession to Invoke-SshCommand works." {
$Result = Get-SshSession -ComputerName $ComputerName | Invoke-SshCommand -Quiet -Command "echo 'This is a test'" `
-ErrorAction Stop
$Result[0] | Should -Be "This is a test"
$Result[0].Result | Should -Be "This is a test"
}

It "Test New-SshSession's -Reconnect parameter" {
It "The -Reconnect parameter for New-SshSession works." {
$Result = New-SshSession -ComputerName $ComputerName -Reconnect -Credential $Global:PesterSSHSessionsCredentials `
-ErrorAction SilentlyContinue
$Result | Should -Match "\[$([Regex]::Escape($ComputerName))\] Successfully connected"
}

It "Test Remove-SshSession" {
It "Remove-SshSession works." {
$Result = Remove-SshSession -ComputerName $ComputerName -ErrorAction SilentlyContinue
$Result | Should -Match "\[$([Regex]::Escape($ComputerName))\] Now disconnected and disposed"
}
Expand Down
123 changes: 88 additions & 35 deletions SSHSessions.psd1
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# Module manifest for module 'SSH-Sessions.psm1'
#
# Created by: Joakim Svendsen
# Module manifest for module 'PSGET_SSHSessions'
#
# Created on: 2012-04-19
# Generated by: Joakim Borger Svendsen
#
# 1.9 - Add -Reconnect to New-SshSession. Standardize output more to Ansible style.
# Generated on: 12/30/2017
# v1.9 - Add -Reconnect to New-SshSession. Standardize output more to Ansible style.
# Some breaking changes if output is parsed, due to this.
#
# v1.9.1 - Add -ScriptBlock to Invoke-SshCommand.
# v1.9.2 - Bug fixes and improvements. Vastly improved pipeline handling.
# v2.0 - Emit objects instead of strings. Majorly breaking change, but
# I think it's needed and much better. Have been considering switching
# to Write-Verbose for a lot of the output and have it quiet, as is
# the convention, but I imagine that after 6 years in the wild, there are
# thousands of meta scripts using this module - and some might be parsing
# the output to determine success. I will look into redesigning and
# standardizing further. Pushing this for now.

@{

# Script module or binary module file associated with this manifest
# Script module or binary module file associated with this manifest.
RootModule = 'SSHSessions.psm1'

# Version number of this module.
ModuleVersion = '1.9'
ModuleVersion = '2.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '65be3f86-9eda-469a-9b2f-2cca1840bbf6'
Expand All @@ -29,64 +40,106 @@ CompanyName = 'Svendsen Tech'
Copyright = 'Copyright (c) 2012-2017, Joakim Borger Svendsen, Svendsen Tech. All rights reserved.'

# Description of the functionality provided by this module
Description = "Svendsen Tech's SSH-Sessions module provides SSH session creation, management and interaction from PowerShell. Lets you execute commands via SSH against Linux and certain network equipment, etc. MIT license. Online documentation here: http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library"
Description = 'Svendsen Tech''s SSH-Sessions module provides SSH session creation, management and interaction from PowerShell. Lets you execute commands via SSH against Linux and certain network equipment, etc. MIT license. Online documentation here: http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '3.0'

# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''
# PowerShellHostVersion = ''

# Minimum version of the .NET Framework required by this module
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
DotNetFrameworkVersion = '4.0'

# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = ''
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = ''
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @('Renci.SshNet.dll')
RequiredAssemblies = 'Renci.SshNet.dll'

# Script files (.ps1) that are run in the caller's environment prior to importing this module
ScriptsToProcess = @()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = @()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module
FunctionsToExport = @("New-SshSession", "Invoke-SshCommand", "Enter-SshSession",
"Remove-SshSession", "Get-SshSession", "ConvertFrom-SecureToPlain")
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'New-SshSession', 'Invoke-SshCommand', 'Enter-SshSession',
'Remove-SshSession', 'Get-SshSession', 'ConvertFrom-SecureToPlain'

# Cmdlets to export from this module
CmdletsToExport = ''
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = ''
# VariablesToExport = @()

# Aliases to export from this module
AliasesToExport = ''
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
ModuleList = @()
# ModuleList = @()

# List of all files packaged with this module
FileList = @('Renci.SshNet.dll', 'SSHSessions.psm1', 'SSHSessions.psd1')
FileList = 'Renci.SshNet.dll', 'SSHSessions.psm1', 'SSHSessions.psd1'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('SSH', 'Linux', 'Unix', 'Cisco', 'Juniper', 'Networking')

# A URL to the license for this module.
# LicenseUri = ''

# A URL to the main website for this project.
# ProjectUri = ''

# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''
# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '# Add a -ScriptBlock parameter for Invoke-SshCommand (less escaped quotes).
# Vastly improved pipeline handling.
# v2.0 - Emit objects instead of strings. Majorly breaking change, but
# I think it''s needed and much better. Have been considering switching
# to Write-Verbose for a lot of the output and have it quiet by default (New/Remove), as is
# the convention, but I imagine that after 6 years in the wild, there are
# thousands of meta scripts using this module - and some might be parsing
# the output to determine success. I will look into redesigning and
# standardizing further. Pushing this for now.'

# External dependent modules of this module
# ExternalModuleDependencies = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

Loading

0 comments on commit 229aa61

Please sign in to comment.