forked from jrussellfreelance/powershell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-apt-upgrade-ubuntu.ps1
More file actions
26 lines (26 loc) · 1.04 KB
/
Copy pathssh-apt-upgrade-ubuntu.ps1
File metadata and controls
26 lines (26 loc) · 1.04 KB
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
# This script performs a software update on a Ubuntu or Debian server
# Grab server IP
Do {
$server = Read-Host "Please enter the IP of the Linux server"
}
While ($server -eq "")
# Grab credentials
$creds = Get-Credential
$user = $creds.UserName
# Create SSH session
$session = New-SSHSession -ComputerName $server -Credential $creds
# Start Shell Stream
$stream = $session.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000)
# Run apt=get update
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "apt-get update" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password
# Wait 30 seconds for apt-get update to run
Start-Sleep -Seconds 30
$return = $stream.Read()
Write-Host $return
# Run apt=get upgrade
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "apt-get upgrade" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password
# Wait 2 minutes for apt-get upgrade to run
Start-Sleep -Seconds 120
$return = $stream.Read()
Write-Host $return
Remove-SSHSession -SessionId 0