-
Notifications
You must be signed in to change notification settings - Fork 11
/
GetShowTech.ps1
141 lines (121 loc) · 5.67 KB
/
GetShowTech.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<#
.Synopsis
GetShowTech.ps1
.DESCRIPTION
This script will collect Show Tech-Support from single or multiple switches
.EXAMPLES
Invoke-GetShowTech
#>
Function Invoke-GetShowTech {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = 'High')]
param([Parameter(Mandatory=$False)]
[string] $CaseNumber)
Remove-Variable * -ErrorAction SilentlyContinue
Clear-Host
$DateTime=Get-Date -Format yyyyMMdd_HHmmss
Start-Transcript -NoClobber -Path "C:\programdata\Dell\GetShowTech\GetShowTech_$DateTime.log"
$text=@"
v1.12
___ _ ___ _ _____ _
/ __|___| |_/ __| |_ _____ __ _|_ _|__ __| |_
| (_ / -_) _\__ \ ' \/ _ \ V V / | |/ -_) _| ' \
\___\___|\__|___/_||_\___/\_/\_/ |_|\___\__|_||_|
By: Jim Gandy
"@
Write-Host $text
Write-Host ""
Write-Host " This tool is used to collect Dell switch logs"
Write-Host ""
if ($PSCmdlet.ShouldProcess($param)) {
# Check if OpenSSH.Client is avaliable in PowerShell
Try{$ChkIfSSHInstalled=Get-WindowsCapability -Online -Name OpenSSH.Client*}
Catch{
$ChkIfSSHInstalled ="FAILED"
Write-Host " OpenSSH.Client NOT available for this OS. Please follow this link to manually collect Show Tech-Support" -BackgroundColor Red -ForegroundColor White
Write-Host " https://www.dell.com/support/kbdoc/en-gy/000116043/dell-emc-networking-how-to-use-putty-exe-to-save-output-to-a-file"
Pause
}
IF($ChkIfSSHInstalled -ine "FAILED"){
# Fix 8.3 temp paths
$MyTemp=(Get-Item $ENV:Temp).fullname
# Collect Show Techs
Write-Host "Gathering Show Tech-Support(s)..."
# Get Case #
if (-not ($Casenumber)) {$CaseNumber = Read-Host -Prompt "Please enter relevant case number or Service tag"}
# Get switch IP addresses
$SwIPs=Read-Host "Please enter comma delimited list of switch IP addresse(s)"
$i=0
IF($SwIPs -imatch ','){$SwIPs=($SwIPs -split ',').Trim()}
While(($SwIPs.count -eq ($SwIPs | %{[IPAddress]$_.Trim()}).count) -eq $False){
$i++
Write-Host "WARNING: Not a valid IP. Please try again." -ForegroundColor Yellow
$SwIPs=Read-Host "Please enter comma delimited list of switch IP addresses"
IF($SwIPs -imatch ','){$SwIPs=$SwIPs -split ','}
IF($i -ge 2){
Write-Host "ERROR: Too many attempts. Exiting..." -ForegroundColor Red
break script
}
}
# Get switch user
IF($SwIPs.count -gt 1){
$SwIPs=$SwIPs -split ','
$SwSameUser=Read-Host "Use the same user for all switches?[Y/N]"
Write-Host "For security reasons a password will need to be provided for each switch."
}
IF($SwSameUser -ieq 'y'){$SWUser=Read-Host "Please enter user name"}
# Add SSH Client
$ChkIfSSHInstalled=Get-WindowsCapability -Online -Name OpenSSH.Client*
IF($ChkIfSSHInstalled.state -ne 'Installed'){
Write-Host "Adding SSH Client..."
Add-WindowsCapability -Online -Name OpenSSH.Client > $null
}
# Clean up old switch logs
IF(Test-Path $MyTemp\ShowTechs){Remove-Item "$MyTemp\ShowTechs" -Recurse -Confirm:$false -Force > $null}
# Create temp folder
Write-Host "Creating temp output location..."
New-Item -Path $MyTemp -Name ShowTechs -ItemType Directory -Force > $null
#Test-Path C:\Users\JIM~1.GAN\AppData\Local\Temp\ShowTechs
# Gathering the show techs
ForEach($SwIp in $SwIPs){
IF($SwSameUser -ine 'y'){
# Switch creds
$SwUser=Read-Host "Please enter user name for switch $SwIP"
}
# Connect to switch
Write-Host "Collecting Show Tech-Support for $SwIP..."
$Switchout=ssh $SwIp -l $SwUser -o StrictHostKeyChecking=no show tech-support
$Switchout | Out-File -FilePath "$MyTemp\ShowTechs\$($SwIp)_ShowTech.log" -Force
}
# Zip up show techs
Write-Host "Compressing show techs..."
$DT=Get-Date -Format "yyyyMMddHHmm"
IF(Test-Path -Path "$MyTemp\logs"){
$ZipPath="$MyTemp\logs\ShowTechs_$($CaseNumber)_$($DT).zip"
Compress-Archive -Path "$MyTemp\ShowTechs\*.*" -DestinationPath "$MyTemp\logs\ShowTechs_$($CaseNumber)_$($DT)"
Write-Host "Logs can be found here: $MyTemp\logs\ShowTechs_$($DT).zip"
}Else{
$OutFolder=$MyTemp+"\Logs"
$ZipPath="$MyTemp\logs\ShowTechs_$($CaseNumber)_$($DT).zip"
New-Item -ItemType Directory -Force -Path $OutFolder >$null 2>&1
Compress-Archive -Path "$MyTemp\ShowTechs\*.*" -DestinationPath "$MyTemp\logs\ShowTechs_$($CaseNumber)_$($DT)"
Write-Host "Logs can be found here: ShowTechs_$($CaseNumber)_$($DT).zip"
}
#Get the File-Name without path
$name = (Get-Item $ZipPath).Name
}
# Clean up show techs
Write-Host "Clean up..."
Remove-Item "$MyTemp\ShowTechs" -Recurse -Confirm:$false -Force
# Remove SSH if installed during this script
IF($ChkIfSSHInstalled.state -ne 'Installed'){
Write-Host "Removing SSH Client..."
Remove-WindowsCapability -Online -Name $ChkIfSSHInstalled.name > $null
}
# Remove Function:\Invoke-GetShowTech
Remove-Item -Path Function:\Invoke-GetShowTech > $null
Stop-Transcript
}
} #end if ShouldProcess
# end of Invoke-GetShowTech