-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoke-RemoteUpdate.ps1
More file actions
38 lines (26 loc) · 1.12 KB
/
Invoke-RemoteUpdate.ps1
File metadata and controls
38 lines (26 loc) · 1.12 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
27
28
29
30
31
32
33
34
35
36
37
38
## deprecated as pswindowsupdate module exisits
Function Invoke-RemoteUpdate{
#A command to scan for and install Windows updates on a remote system.
Param(
[parameter(position=0)]
$ComputerName,
[parameter(position=1)]
$Credential
)
if ($ComputerName -eq $NULL){
$ComputerName = Read-Host -Prompt "Input hostname for update target"
}
$isup = Test-Connection -ComputerName $ComputerName -Count 1 -ErrorAction SilentlyContinue
if ($isup -eq $NULL) {Out-Host -InputObject "$ComputerName is not avalible. Either the name is incorrect or the host is offline."}
if ($isup -ne $NULL) {
if ($Credential.username -eq $NULL -or $Credential -eq $NULL){ $credential = Get-Credential -Credential $Credential }
try {
$S1 = New-PSSession -ComputerName $ComputerName -Credential $credential -ErrorAction Stop
Invoke-Command -Session $S1 -ScriptBlock { UsoClient.exe } -ArgumentList ScanInstallWait
Invoke-Command -Session $S1 -ScriptBlock { UsoClient.exe } -ArgumentList StartInstall
Remove-PSSession -Session $S1 -ErrorAction SilentlyContinue
Out-Host -InputObject "$ComputerName is updating"
}
catch {
Write-Host "Username or Password incorrect."
}}}