iex (New-Object Net.WebClient).DownloadString("https://gist.github.com/darkoperator/6152630/raw/c67de4f7cd780ba367cccbc2593f38d18ce6df89/instposhsshdev")
Find-Module Posh-SSH | Install-Module
Get-Command -Module Posh-SSH
Import-Module Posh-SSH $SSHSession = New-SSHSession -ComputerName 192.168.1.1 -Credential $(Get-Credential) -Verbose
$SSH = $SSHSession | New-SSHShellStream
# $SSH.WriteLine( "enable" ) # $SSH.read()
$sshSession | Remove-SSHSession
$SwitchIP = '10.10.3.2' $SwitchPort = 4 $Cred = Get-Credential admin $SSHSession = New-SSHSession -ComputerName $SwitchIP -Credential $Cred -Verbose if ($($sshSession.Connected) -eq $true) { Write-Host "SSH session opened" -ForegroundColor Green Write-Host " " Write-Host " open shell" -ForegroundColor Green ### , $ssh = $sshSession | New-SSHShellStream Start-Sleep -Seconds 1 # $ssh.read() Start-Sleep -Seconds 1 $ssh.WriteLine( "enable" ) $ssh.read() Write-Host " " -ForegroundColor Green Start-Sleep -Seconds 1 $ssh.WriteLine( "password" ) $ssh.read() Write-Host " " -ForegroundColor Green Start-Sleep -Seconds 1 $ssh.WriteLine( "configure" ) $ssh.read() Write-Host " " -ForegroundColor Green Start-Sleep -Seconds 1 $ssh.WriteLine( "interface gigabitEthernet 1/0/$SwitchPort" ) $ssh.read() Write-Host " interface gigabitEthernet 1/0/$SwitchPort" -ForegroundColor Green Start-Sleep -Seconds 1 $ssh.WriteLine( "shutdown" ) $ssh.read() Write-Host " " -ForegroundColor Green Start-Sleep -Seconds 3 $ssh.WriteLine( "no shutdown" ) $ssh.read() Write-Host " " -ForegroundColor Green Write-Host " , " -ForegroundColor Green } else { Write-Host "SSH session cannot be established" -ForegroundColor Red Write-Host "script terminate" -ForegroundColor Red exit } if ( $($sshSession | Remove-SSHSession) -eq $true) { Write-Host "SSH session closed" -ForegroundColor Green } else{ Write-Host "SSH session NOT closed" -ForegroundColor Red Write-Host "please check manual" -ForegroundColor Red Get-SSHSession }
Set-SCPFile -LocalFile .\Downloads\VMware-PowerCLI-5.5.0-1671586.exe -RemoteFile "/tmp/powercliinstaller.exe" -ComputerName 192.168.10.3 -Credential (Get-Credential root)
Get-SCPFile -LocalFile .\Downloads\VMware-PowerCLI.exe -RemoteFile "/tmp/powercliinstaller.exe" -ComputerName 192.168.10.3 -Credential (Get-Credential root)
Source: https://habr.com/ru/post/314990/
All Articles