PoshCode Archive  Check-in [0f81aa8c25]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:As promised, I started to expand on Joel’s functions (http://poshcode.org/877). A lot of stuff is missing, but… I have big plans for this module and a PKI module I want to write.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:0f81aa8c259f7c6cfd72c42c6a96d908780ead925f3e8df9e29f087f17d07f63
User & Date: tysonkopczynski 2018-06-10 14:27:48
Context
2018-06-10
14:27
Generates a Linux VMDK Backup Script check-in: 5c57dea9b6 user: Patrick tags: trunk
14:27
As promised, I started to expand on Joel’s functions (http://poshcode.org/877). A lot of stuff is missing, but… I have big plans for this module and a PKI module I want to write. check-in: 0f81aa8c25 user: tysonkopczynski tags: trunk
14:27
Given an IP address and subnet mask return all alive hosts within that subnet. Uses PSJobs as a poor mans threading thus requires V2. check-in: 8feeed53f3 user: glnsize tags: trunk
Changes

Changes to SharpSSH-Module.ps1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# encoding: ascii
# api: powershell
# title: SharpSSH Module
# description: I fixed some stuff.
# version: 0.1
# type: function
# author: tysonkopczynski
# license: CC0
# function: New-SharpSession
# x-poshcode-id: 1034
# x-archived: 2011-12-30T04:50:02
# x-published: 2011-04-16T00:51:00
#
# As promised, I started to expand on Joel’s functions (http://poshcode.org/877).  A lot of stuff is missing, but… I have big plans for this module and a PKI module I want to write.
#
##################################################
# cmdlets
##################################################
#-------------------------------------------------
# New-SharpSession
#-------------------------------------------------
# Usage:		New-SharpSession -?
#-------------------------------------------------
function New-SharpSession {
	<# 
	.Synopsis
    	Used to open an SSH or SCP Session to the specified server.
    .Description
    	Uses SharpSSH to open an SSH or SCP Session to the specified server.
	.Parameter Host
    	The hostname or IP address that you want to connect to.
	.Parameter UserName
    	The username string used for the connection.
    .Parameter Key
    	The switch that tells function to execute with key parameters.
    .Parameter KeyFile
    	The path and file name to the key file used for key based
    	authentication.
    .Parameter User
    	The switch that tells function to execute with user parameters.
    .Parameter Password
    	The password string used for the connection.
	#> 
    [CmdletBinding(DefaultParameterSetName="KeySet")]
    param(
		[Parameter(Mandatory=$True)][String]$Host,
		[Parameter(Mandatory=$True)][String]$UserName,
		[Parameter(ParameterSetName="KeySet")][Switch]$Key,
        [Parameter(ParameterSetName="KeySet", Mandatory=$True)][String]$KeyFile,
        [Parameter(ParameterSetName="User")][Switch]$User,
        [Parameter(ParameterSetName="User", Mandatory=$True)][String]$Password,
		[Switch]$SCP,
		[Switch]$PassThru
        )
	
	try {
		# Default will always be to do SSH...
		if ($SCP){
			$ConnectType = "Tamir.SharpSsh.scp"
			}
................................................................................
			}
		
		if($PassThru){
			return $Global:SharpSession
			}
		}
	catch {
		throw $_
		}
	}

#-------------------------------------------------
# Transfer-SharpFile
#-------------------------------------------------
# Usage:		Transfer-SharpFile -?
#-------------------------------------------------
function Transfer-SharpFile {
	<# 
	.Synopsis
    	Used to tranfser(get or put) a file using a valid SCP SharpSession.
    .Description
    	Uses SharpSSH to tranfer (get or put) a file via SCP.
	.Parameter From
    	The full path and file name to the file you are transferring.
	.Parameter To
    	The full path and file name to where you want to copy the file to.
	#> 
    param(
		[Parameter(Mandatory=$True)][String]$From,
		[Parameter(Mandatory=$True)][String]$To,
		[Switch]$Get,
		[Switch]$Put
		)
	
	try {
		if (!($Get -or $Put)) {
			throw Write-Host "Get or Put must be defined!" -ForeGroundColor Red
			}
	
................................................................................
				catch{
					Write-Warning "File is not there..."
					}
				}
			}
		}
	catch {
		throw $_
		}
	finally {
		if (Get-EventSubscriber -SourceIdentifier Scp.OnTransferProgress){
			[void] (Unregister-Event -SourceIdentifier Scp.OnTransferProgress)
			}
		if (Get-EventSubscriber -SourceIdentifier Scp.OnTransferEnd){
			[void] (Unregister-Event -SourceIdentifier Scp.OnTransferEnd)
................................................................................
#-------------------------------------------------
# Remove-SharpSession
#-------------------------------------------------
# Usage:		Remove-SharpSession -?
#-------------------------------------------------
function Remove-SharpSession {
	<# 
	.Synopsis
    	Used to close an active SSH or SCP Session.
    .Description
    	Uses SharpSSH to close an active SSH or SCP Session.
	#> 
	
	try {
		if($SharpSession){
................................................................................
				}
			}
		else{
			throw "There is no session to remove!"
			}
		}
	catch {
		throw $_
		}
	finally {
		$Global:SharpSession = $Null
		}
	}	
	
##################################################
# Main
##################################################
Export-ModuleMember New-SharpSession
Export-ModuleMember Transfer-SharpFile
Export-ModuleMember Remove-SharpSession



|





|
|
|

<











|



|

|













|
|
|



|
|







 







|










|



|

|



|
|
|
|







 







|







 







|







 







|












1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# encoding: ascii
# api: powershell
# title: SharpSSH Module
# description: As promised, I started to expand on Joel’s functions (http://poshcode.org/877).  A lot of stuff is missing, but… I have big plans for this module and a PKI module I want to write.
# version: 0.1
# type: function
# author: tysonkopczynski
# license: CC0
# function: New-SharpSession
# x-poshcode-id: 979
# x-archived: 2011-12-30T05:26:42
# x-published: 2011-03-29T04:31:00
#

#
##################################################
# cmdlets
##################################################
#-------------------------------------------------
# New-SharpSession
#-------------------------------------------------
# Usage:		New-SharpSession -?
#-------------------------------------------------
function New-SharpSession {
	<# 
    .Synopsis
    	Used to open an SSH or SCP Session to the specified server.
    .Description
    	Uses SharpSSH to open an SSH or SCP Session to the specified server.
    .Parameter Host
    	The hostname or IP address that you want to connect to.
    .Parameter UserName
    	The username string used for the connection.
    .Parameter Key
    	The switch that tells function to execute with key parameters.
    .Parameter KeyFile
    	The path and file name to the key file used for key based
    	authentication.
    .Parameter User
    	The switch that tells function to execute with user parameters.
    .Parameter Password
    	The password string used for the connection.
	#> 
    [CmdletBinding(DefaultParameterSetName="KeySet")]
    param(
	[Parameter(Mandatory=$True)][String]$Host,
	[Parameter(Mandatory=$True)][String]$UserName,
	[Parameter(ParameterSetName="KeySet")][Switch]$Key,
        [Parameter(ParameterSetName="KeySet", Mandatory=$True)][String]$KeyFile,
        [Parameter(ParameterSetName="User")][Switch]$User,
        [Parameter(ParameterSetName="User", Mandatory=$True)][String]$Password,
	[Switch]$SCP,
	[Switch]$PassThru
        )
	
	try {
		# Default will always be to do SSH...
		if ($SCP){
			$ConnectType = "Tamir.SharpSsh.scp"
			}
................................................................................
			}
		
		if($PassThru){
			return $Global:SharpSession
			}
		}
	catch {
		throw $Error[0]
		}
	}

#-------------------------------------------------
# Transfer-SharpFile
#-------------------------------------------------
# Usage:		Transfer-SharpFile -?
#-------------------------------------------------
function Transfer-SharpFile {
	<# 
    .Synopsis
    	Used to tranfser(get or put) a file using a valid SCP SharpSession.
    .Description
    	Uses SharpSSH to tranfer (get or put) a file via SCP.
    .Parameter From
    	The full path and file name to the file you are transferring.
    .Parameter To
    	The full path and file name to where you want to copy the file to.
	#> 
    param(
	[Parameter(Mandatory=$True)][String]$From,
	[Parameter(Mandatory=$True)][String]$To,
	[Switch]$Get,
	[Switch]$Put
		)
	
	try {
		if (!($Get -or $Put)) {
			throw Write-Host "Get or Put must be defined!" -ForeGroundColor Red
			}
	
................................................................................
				catch{
					Write-Warning "File is not there..."
					}
				}
			}
		}
	catch {
		throw $Error[0]
		}
	finally {
		if (Get-EventSubscriber -SourceIdentifier Scp.OnTransferProgress){
			[void] (Unregister-Event -SourceIdentifier Scp.OnTransferProgress)
			}
		if (Get-EventSubscriber -SourceIdentifier Scp.OnTransferEnd){
			[void] (Unregister-Event -SourceIdentifier Scp.OnTransferEnd)
................................................................................
#-------------------------------------------------
# Remove-SharpSession
#-------------------------------------------------
# Usage:		Remove-SharpSession -?
#-------------------------------------------------
function Remove-SharpSession {
	<# 
    .Synopsis
    	Used to close an active SSH or SCP Session.
    .Description
    	Uses SharpSSH to close an active SSH or SCP Session.
	#> 
	
	try {
		if($SharpSession){
................................................................................
				}
			}
		else{
			throw "There is no session to remove!"
			}
		}
	catch {
		throw $Error[0]
		}
	finally {
		$Global:SharpSession = $Null
		}
	}	
	
##################################################
# Main
##################################################
Export-ModuleMember New-SharpSession
Export-ModuleMember Transfer-SharpFile
Export-ModuleMember Remove-SharpSession