Ejercicios de PowerShell: SSH

Instalar y ejecutar SSH para PowerShell

Install-Module -Name Posh-SSH -RequiredVersion 2.0.2
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
New-SSHSession -ComputerName 10.0.2.11 -Credential (Get-Credential)

Conexión después de haber desconectado y quitado el módulo Posh-SSH (hay que volver a importarlo)

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Import-Module Posh-SSH

New-SSHSession -ComputerName 10.20.104.19 -Credential (Get-Credential)

Get-SSHSession

(Invoke-SSHCommand -Index 0 "uname -r").output

(Invoke-SSHCommand -Index 0 "lscpu").output | Out-File informacionunubntu.txt -Append
(Invoke-SSHCommand -Index 0 "lshw").output | Out-File informacionunubntu.txt -Append
(Invoke-SSHCommand -Index 0 "nproc").output | Out-File informacionunubntu.txt -Append

Ejemplo: obtener información sobre la versión de Linux

Install-Module -Name Posh-SSH -RequiredVersion 2.0.2
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
New-SSHSession -ComputerName 10.0.2.14 -Credential (Get-Credential)
Get-SSHSession
Invoke-SSHCommand -Index 0 "uname"

Ejemplo: obtener información sobre la CPU

# Realizar la conexión SSH
Install-Module -Name Posh-SSH -RequiredVersion 2.0.2
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
New-SSHSession -Computer
# Obtener información sobre el procesador desde Linux mediante una conexión SSH
(Invoke-SSHCommand -Index 0 "bash -c lscpu | grep '32-bit'")
(Invoke-SSHCommand -Index 0 "bash -c lscpu | grep '32-bit' | cut -d':' -f2  | cut -d'-' -f1 ").output
# ¿Es intel?
(Invoke-SSHCommand -Index 0 "lscpu").output
if((Invoke-SSHCommand -Index 0 "lscpu").output -match "Intel"){"Intel"}else{"No es Intel"}
(Invoke-SSHCommand -Index 0 "lscpu").output | select-string "cache"