Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2353668

Browse files
Add sync-WsusClient to force computers to check in with update server
1 parent 66f645a commit 2353668

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function sync-WsusClient {
2+
<#
3+
.SYNOPSIS
4+
Function to force the given computer(s) to check for updates and check in with the WSUS server
5+
.DESCRIPTION
6+
Connects to computer list over WinRM (PsSession) and forces it to check for updates and report to its WSUS server
7+
Default if no computers listed is to use localhost
8+
Meant to run against many computers and get quick results
9+
.PARAMETER ComputerName
10+
A string list of computer names against which to run this sync command
11+
.PARAMETER Credential
12+
A "pscredential" that will be used to connect to the remote computer(s)
13+
.EXAMPLE
14+
Sync-WsusClient
15+
"localhost - Done!"
16+
.EXAMPLE
17+
Sync-WsusClient server1, server2, server3, server4
18+
"server2 - Done!"
19+
"server1 - Done!"
20+
"server4 - Done!"
21+
"server3 - Done!"
22+
.EXAMPLE
23+
Sync-WsusClient server1, server2 -Credential admin
24+
(enter your credential and then...)
25+
"server2 - Done!"
26+
"server1 - Done!"
27+
.NOTES
28+
Here's one place where it came from: http://pleasework.robbievance.net/howto-force-really-wsus-clients-to-check-in-on-demand/
29+
Roger P Seekell, (2019), 9-13-2019
30+
#>
31+
Param(
32+
[Parameter(ValueFromPipeline=$true,
33+
ValueFromPipelineByPropertyName=$true)]
34+
[string[]]$ComputerName = 'localhost',
35+
[pscredential]$Credential = $null
36+
)
37+
process {
38+
#this script block will run on each computer
39+
$scriptBlock = {
40+
try {
41+
$updateSession = New-Object -com "Microsoft.Update.Session"
42+
$null = $updateSession.CreateUpdateSearcher().Search($criteria).UPdates #I don't want to see them
43+
wuauclt /reportnow
44+
"$env:computername - Done!"
45+
}
46+
catch {
47+
Write-Error "Sync unsuccessful on $env:computername : $_"
48+
}
49+
}#end script block
50+
51+
$splat = @{"ComputerName" = $ComputerName; "ScriptBlock" = $scriptBlock}
52+
53+
if ($Credential -ne $null) {
54+
$splat += @{"Credential" = $Credential}
55+
}
56+
57+
Invoke-Command @splat #run with the two or three parameters above
58+
}#end process
59+
60+
}#end function

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /