-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconsole.ps1
122 lines (106 loc) · 2.85 KB
/
console.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
115
116
117
118
119
120
121
122
<#
.SYNOPSIS
[Incomplete script!] This is a template for new scripts
.DESCRIPTION
[Incomplete script!] This is a template for new scripts
.EXAMPLE
C:\PS>.\template.ps1
This will bring up the new script
.INPUTS
There are no inputs that can be directed to this script
.OUTPUTS
All outputs are sent to the console and logged in the log folder
.NOTES
Author: Robert Weber
Date: Nov 19, 2015
#>
[CmdletBinding()]
param (
$computerName = "128.38.160.102",
$port = 22,
$username = "rweber",
$password = "SharkTeeth12!@"
)
if($pwd -ne (split-path $MyInvocation.MyCommand.definition)){
set-location (split-path $MyInvocation.MyCommand.definition)
}
clear
$error.clear()
. .\lib\PSClass.ps1
(gci .\lib) | % { . "$($_.FullName)" }
$testClass = new-PSClass something{
note -static PsScriptName "consolePutty"
note -static Description ( ($(((get-help .\console.ps1).Description)) | select Text).Text)
note -private computerName
note -private port
note -private username
note -private password
note -private sshClient
note -private sshStream
note -private reader
note -private writer
note -private new $true
constructor{
param()
if( ('renci.SshNet.SshClient' -is [type] ) -eq $false){
add-type -path "$($pwd)\bin\Renci.SshNet35.dll"
}
$private.computerName = $computerName
$private.port = $port
$private.username = $username
$private.password = $password
$private.sshClient = new-object Renci.SshNet.SshClient(
$($private.computerName),
$($private.port),
$($private.username),
$($private.password)
)
try{
$private.sshClient.Connect()
}catch{
write-error $_.Exception.Message
break;
}
$private.sshStream = $private.sshClient.CreateShellStream("psshell", 80, 24, 800, 600, 1024)
$private.reader = new-object System.IO.StreamReader($private.sshStream)
$private.writer = new-object System.IO.StreamWriter($private.sshStream)
$private.writer.AutoFlush = $true
}
method readStream{
while ($private.sshStream.Length -eq 0){
start-sleep -milliseconds 500
}
$content = $private.reader.ReadToEnd()
$lines = $content -split "`n"
for($i = 1; $i -lt $lines.count - 2; $i++){
write-host "$($lines[$i])"
}
start-sleep -milliseconds 500
if($private.sshStream.dataAvailable -eq $true){
$this.readStream()
}
}
method Execute{
param()
$host.ui.rawui.backgroundColor = 0
$host.ui.rawui.foregroundColor = 7
clear;
$this.readStream();
while(1){
$command = Read-Host -Prompt "$($private.username)@$($private.computerName)]`$"
if($command -eq 'quit'){
break
}
$private.writer.WriteLine($command)
$this.readStream();
}
$host.ui.rawui.backgroundColor = 5
$host.ui.rawui.foregroundColor = 15
clear
$private.sshStream.Dispose()
$private.sshClient.disconnect()
$private.sshClient.dispose()
$uiClass.errorLog()
}
}
$testClass.New().Execute() | out-null